I am new to Laravel 5 and trying to understand its Auth
process. I want to prevent user to reach some of my pages unless the user is not logged in. Trying to make it with Route:filter
but it does not work. What i have done wrong ?
Route::filter('/pages/mainpage', function()
{
if(!Auth::check())
{
return Redirect::action('PagesController@index');
}
});
if you want authentication middleware for single route then
if you want auth middlesware on multiples routes then use :
you can do this directly in your blade code by this way
You should use the
auth
middleware. In your route just add it like this:Or in your controllers constructor:
U can use midlleware in colntroller
All actions in controller require to be logged in
Or u can check it in action
also u can use it on route
use
more here https://laravel.com/docs/5.2/authentication#authenticating-users in Determining If The Current User Is Authenticated