Laravel after login, redirect back to previous url ?

By Hardik Savani | January 15, 2016 | | 9030 Viewer | Category : Laravel


Share this post:



If you are working on laravel and you want to do like: How to redirect back to previous url, After login. after login user you can redirect his previous page as he was before. you can do this, i would like to give you two example. first example is using intended() and second one is using session but i don't know more but i think intended() is not working proper in laravel 5 but you can try in laravel 4. but i am sure i gave you example with session that work well in both.

So, you can try any one and get your solution, 1. using intended() and 2. session.

Example 1:

public function loginPost()

{

if ($this->auth->attempt(array('email' => Input::get('email'), 'password' => Input::get('password')))){

return Redirect::intended();

}

return back();

}

Example 2:

public function login()

{

Session::put('url.intended',URL::previous());

return view('login');

}

public function loginPost()

{

if ($this->auth->attempt(array('email' => Input::get('email'), 'password' => Input::get('password')))){

return Redirect::to(Session::get('url.intended'));

}

return back();

}

Try this........