Using session to reach previous page after login in laravel

1.5k views Asked by At

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?

2

There are 2 answers

0
whatTheCase On BEST ANSWER

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')

0
Jesus Erwin Suarez On

Use this in your login controller

url()->previous()