Laravel 5 after login, redirect back to previous/intended url ?

Laravel 5 after login, redirect back to previous/intended url ?

In this post, i will tell you how to redirect user back to URL they were trying to access before login using intended method.

You can also save the previous url in session so that you can easily redirect back to their previous url after authentication filter.

Example 1 : Using intended method
  1. public function auth()
  2. {
  3. if (Auth::attempt(['email' => $email, 'password' => $password])) {
  4. // Authentication passed...
  5. return redirect()->intended('dashboard');
  6. }
  7. }
Example 2: Using Session
  1. public function getLogin(Request $request)
  2. {
  3. $request->session()->put('url.intended',url()->previous());
  4. return view('login');
  5. }
  6. public function postLogin(Request $request)
  7. {
  8. if (Auth::attempt(['email' => $email, 'password' => $password])) {
  9. return redirect($request->session()->get('url.intended'));
  10. }
  11. return back();
  12. }

Phone: (+91) 8800417876
Noida, 201301
sakarya escort sakarya escort bayan sakarya escort serdivan escort sakarya escort sakarya escort serdivan escort
karasu escort akyazı escort serdivan escort akyazı escort ferizli escort sapanca escort serdivan escort söğütlü escort sakarya escort izmit escort arifiye escort erenler escort hendek escort kocaali escort pamukova escort taraklı escort geyve escort