I want to redirect back user to entered url after authenticating user Scenario is: User enter a url, in backend I check for user to be authenticated and if user does not authenticated redirect user to login url and after successful login redirect user back to first url that user entered
Users Controller:
public function index()
{
if(!Auth::check())
{
return View::make('adminLogin');
}
return Redirect::to('admin');
}
public function login()
{
$creds = array(
'username' => Input::get('username'),
'password' => Input::get('password')
);
if (Auth::attempt($creds))
return Redirect::back();
}
routes.php:
Route::resource('users', 'UsersController');
Route::post('login', 'UsersController@login');
filters.php:
Route::filter('logged', function($request)
{
if(!Auth::check())
return Redirect::to('users');
});
SettingController.php:
public function __construct()
{
$this->beforeFilter('logged', array('only' => array('index')));
}
public function index()
{
return View::make('setting');
}
Please help me.I'm a newbie in Laravel.
Use Redirect::intended('/');
instead of Redirect::back();
.
PS: Also change
Route::filter('logged', function($request)
{
if(!Auth::check())
return Redirect::guest(URL::to('users')); //Your login form.
});