4

How can I redirect back page after login? in Laravel 5.2

AuthController

protected $redirectTo = '/';

RedirectUsers

<?php

namespace Illuminate\Foundation\Auth;

trait RedirectsUsers
{
    /**
     * Get the post register / login redirect path.
     *
     * @return string
     */
    public function redirectPath()
    {
        if (property_exists($this, 'redirectPath')) {
            return $this->redirectPath;
        }

        return property_exists($this, 'redirectTo') ? $this->redirectTo : '/';
    }
}
Sanzeeb Aryal
  • 4,358
  • 3
  • 20
  • 43
jungmyung
  • 319
  • 3
  • 13
  • 2
    Just add `return redirect()->back()` in the login function, that's it. Just make sure you don't end up in a redirect loop, it happens. – Andrei Sep 29 '16 at 12:27
  • @Andrew Where I add that code on? I used make:auth in Laravel 5.2 – jungmyung Oct 01 '16 at 09:50
  • https://stackoverflow.com/questions/29954791/laravel-5-after-login-redirect-back-to-previous-page/56095470#56095470 Refer to this answer – Akash Sethi May 12 '19 at 01:30

2 Answers2

0

You can do it by using either of these two options.

  • return Redirect::back(); This will take the user back to the page from where he/she came.
  • return redirect('enter your route here'); This will take the user to the view which you have defined with that particular route.
Chiragh Dewan
  • 367
  • 1
  • 11
0

In your auth function which you've written in the controller. It'll be something like this:

 function xyz() {

  // your function code

  return Redirect::back();
}
Chiragh Dewan
  • 367
  • 1
  • 11