Laravel after login, redirect back to previous url ?

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


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........



Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.