I added a standard authorization filter to several routes using Route :: Intended ('/') in the controller (provided that the login was completed successfully).
filters.php:
Route::filter('auth', function(){
if (Auth::guest()) return Redirect::guest('internal/login');
});
Controller:
if (Auth::attempt($data, false))
{
return Redirect::intended('/');
}
How do I create a custom auth filter that checks for a specific permission (isAdmin in this case)?
I made the auth.admin filter the same as the standard auth filter to redirect to the login page, but do I need a second login method on my controller or is there a way to tell which filter (if any) the controller method is called?
if (Auth::attempt($data, false))
{
if (RouteHasAdminFilter())
{
if (!Auth::User()->Admin)
return Redirect::intended('/');
else
return Redirect::to('/');
}
else
{
return Redirect::intended('/');
}
}
source
share