Search code examples
laravelsessionlaravel-authorization

Using session to reach previous page after login in laravel


I am using Laravel 5.7. For security reasons, I set my laravel application to automatically logout after one hour inactivity. But I want the user log back in the same page before they got kicked out by the system. I try to use Session, but it only store previous url which is the login page url. How can I retrieve that URL before user got automatically logout?


Solution

  • All you need to do is put this in your logout function.

    session(['returnUrl' => url()->previous()]);
    

    And then on login function, redirect user to session('returnUrl') and delete session data with session()->forget('returnUrl')