Im facing problem using filters in laravel. Here is the piece of code
Route::get('admin/login', function()
{
return View::make('admin.login');
});
Route::get('admin/logout', function()
{
Auth::logout();
return Redirect::to('admin/login');
});
Route::post('admin/login', function()
{
$userdata = array('username' => Input::get('username'),
'password' => Input::get('password'));
if (Auth::attempt($userdata))
{
return Redirect::to('admin');
}
else
{
return Redirect::to('admin/login')->with('login_errors',true);
}
});
Route::get('admin', array('before' => 'auth', function() {
return Redirect::to('admin');
}));
Route::filter('auth', function()
{
if (Auth::guest()) return Redirect::to('admin/login');
});
The problem is when im opening /admin, it is redirecting me to the admin/login (which is good). Now if I enter the correct username and password, it should take me to /admin page, but it again redirect me back to admin/login page. I think whenever I want it to redirect me to /admin, the (before auth) filters run and it takes me back to admin/login.
Please Help