I am using laravel for my web application and in routes.php I have:
// admin routes
Route::group(array('before' => 'auth'), function()
{
Route::controller('admin', 'UsersController');
});
I want to protect and check if the person is logged in , but this code always redirect to "/login" i want it to redirect to "admin/login" , can this be done?
Yes. Add the following filter:
I copied original
auth
filter delivered with Laravel.Next, use your new filter:
Complete solution:
There is a default
auth
filter in thefilters.php
file, it should be like this:This filter (given above) will check if the user is not logged in then a redirect will occur and user will be sent to
/login
url
and otherwise nothing will happen, user will be sent to the requested page.Also, following
filter
is available by default and thisfilter
just checks if the user is already logged in then (s)he will be redirected to/
(home page) by default:This (
guest
) filter is used with/login
as given below, so if a logged in user intended to log in then the user will be redirected to home page by default:Now, in your
routes.php
file you have following route declared:If everything is fine then this setup should work. If a logged out user tries to visit
admin
then user will be sent tologin
and these are by default available and should work.