php - advanced authentication routes in laravel 5
i currently have /dashboard route that is behind login page, which after login takes you to admin panel.
Route::get('dashboard', ['middleware' => 'auth', function()
{
return view('dash.dashboard');
}]);
this is working fine. But I can't figure out how to prevent access to all the links in admin panel if not logged in. how can i prevent all the dashboard/{} routes? note - I'm still learning laravel.
Answer
Solution:
You can use Route::group() to wrap all your admin routes and make them use the auth middleware, example :
See more in the documentation
Answer
Solution:
What you can do is, you can create a controller, let's say
DashboardController
and create a route, like the following:And in your
DashboardController
, do this in your constructor:Create other functions in this controller, so everytime, the functions in this controller are called, it will check the auth middleware. This is a good way to do it.
The other way to do it is to use route group.