Laravel after login, redirect back to previous url

If you are working on laravel and you want to do like: How to redirect back to the 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. the first example is using intended() and the second one is using session but I don't know more but I think intended() is not working properly in laravel 5 but you can try in laravel 4. but I am sure I gave you an example with the session that works well in both.

So, you can try anyone 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();

}

Comments

Popular posts from this blog

Laravel 5 Chart example using Charts Package

PHPMyBackup - A PHP MySQL differential backup script

Laravel Stats Tracker