-1

I'm new to using laravel 5.7.

I made a make:auth and to authenticate I need use http://localhost:8000/login and when I login I get redirected to http://localhost:8000/home, but I want login on http://localhost:8000/admin-panel/login and when I auth, I have to redirect to http://localhost:8000/admin-panel/home

Which files I will have to edit?

routes/web.php:

Route::get('/', function () { return view('welcome'); }); 
Auth::routes(['register' => false]);
Route::get('/home', 'HomeController@index')->name('home');
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
c4rlosls
  • 65
  • 9
  • 2
    Hi and welcome to Stack Overflow! Could you please post what you have done in your Web routes or look up routing in the Laravel docs for this answer? https://laravel.com/docs/5.7/routing – party-ring Jan 17 '19 at 16:29
  • Does making a Route::group(['prefix' => 'admin-panel'], function(){ ... }) work? – Tarek Adam Jan 17 '19 at 16:45
  • Only work http://localhost:8000/admin-panel/login but when I initiate session redirect to http://localhost:8000/home. I wanna have an admin section on /admin-panel/ and change all controllers (change home for admin) like HomeController@index to AdminController@index. – c4rlosls Jan 17 '19 at 16:52

2 Answers2

0

routes/web.php

Route::group(['prefix' => 'admin-panel'], function(){
    Route::get('/', function () { return view('welcome'); });
    Auth::routes(['register' => false]);
    Route::get('/home', 'HomeController@index')->name('home');  
});

to see all your routes put this in the command line at your project root

php artisan route:list
Tarek Adam
  • 3,387
  • 3
  • 27
  • 52
  • now work if i enter or admin-panel/home, redirect to admin-panel/login and when i login redirect to admin-panel/home. But if a enter on admin-panel/login and login, redirect to /home – c4rlosls Jan 17 '19 at 17:00
  • okay i fixed it, and how can i change all controllers? i wanna have a make:auth login on /admin-panel/login for administrators and another make:auth /login for normal users, when I create 2 make:auth both will have the same middleware? example: a normal user login on /login and auth restriction allow to show /home but too allow to show /admin-panel/home? – c4rlosls Jan 17 '19 at 17:06
  • I think you should use the authentication controller to direct users based on "roles". In the long run, this will give you great flexibility and clean code. You'll be able to direct your users and guard your routes in a very clean/simple way from one login, one auth guard, and one users table. I use https://github.com/Zizaco/entrust – Tarek Adam Jan 17 '19 at 17:30
  • Then, I use roles and the login in /login and another login in /admin-panel/login (alone this one will allow to connect to the users who have role of administrator). If a normal user enters in /admin-panel/dashboard and role does not have admin that redirection to/admin-panel/login, this way would be? – c4rlosls Jan 17 '19 at 17:47
  • Yes. You'll just have to direct uses to the right place from either the /home controller or from the auth controller – Tarek Adam Jan 17 '19 at 18:26
  • And if i have diferents themes, where i can host it? on resources/views/theme1 and resources/views/theme2? – c4rlosls Jan 17 '19 at 18:45
  • We should keep stack overflow organized. Please mark your question as complete or answered ~ then start a new question for views. – Tarek Adam Jan 17 '19 at 19:13
0

I think your intention is use prefix on route group.

Route::prefix('/admin-panel')->namespace('admin-panel')->group(function()
{                                     
 Route::get('/dashboard', 'AdminController@AdminDashboard')->name('dashboard');
});

After this your route behave like this

 Route::get('/admin-pannel/dashboard', 'admin-pannel/AdminController@AdminDashboard')->name('dashboard');
Vinay Kaithwas
  • 1,415
  • 10
  • 17