Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Redirect to Previous after login

I have a login form and after the form submission (if validation is OK) the browser should redirect to the last page before login. Currently I redirect back and I get always into the same login page. My routes.php is something like this:

Route::get('/', 'HomeController@index');
Route::get('/list','EventController@index');
Route::get('/login','AuthController@login');
Route::post('/login','AuthController@do_login');

And my Redirection inside do_login() is

if(Login_is_valid())
{
    return Redirect::back();
}

If I'm inside /list page and then open Login and fill the form correctly I'm redirected to /login again isn't it weird? Many thanks

like image 653
Diogo Mendonça Avatar asked Jul 01 '15 15:07

Diogo Mendonça


1 Answers

Hello if you use Laravel 5.1 you can redirect to previous page next way

return back();

or you can use Session where Laravel save previous page

return redirect(Session::get('_previous')['url']);
like image 140
dyachenko Avatar answered Sep 28 '22 05:09

dyachenko