Laravel after login, redirect back to previous url ?

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this tutorial i will show how redirect back to previous url after login in laravel. So if you are new to working on laravel and you want to do like that as : How to redirect back to previous url, After login. So after login user we can redirect his previous page as he was before. Here we can do this, i would like to give you very short two example. first example is by using intended() and then second one is by using session but i don’t know more but i think intended() is not working proper in laravel 5 but we can try in laravel 4. But here i am sure i give you example with session that work well in both.

So, now we can try any one and get your solution, 1. by 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();
}

Read Also : How to count number of files in folder and remove all files in folder in laravel example?

Thanks for read this, I hope it will you. You can also follow us onĀ Facebook.

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →