简体   繁体   中英

How to stay on the same page after a logout in Laravel

As the question title suggests, I'm wondering how to set my website up so that the user stays on the same page after a log out. In particular, I'm wondering if Laravel provides syntax to do this. I'm hoping to use best practice for within Laravel.

For example:

The log in link is displayed at the top of every every page. Bob is logged in and viewing the 'about' page. Bob clicks 'Log Out.' Bob is logged out and redirected back to the about page.

I figured this would be a nice way to do it, since the auth filter can then determine if the page is protected or not and redirect accordingly.

I'M ALSO INTERESTED if you think this is bad practice from a usability standpoint. Most examples I've seen have the logout function redirect to the home page. Is there any reason NOT to stay on the same page?

Die you try: return Redirect::back(); In your logout route/controller?

From a usability standpoint, I think it is a very good idea to send the user back to the page they were on after logging out, provided it is not a protected page.

It is actually quite easy to achieve. You need to make your logout link like this: example.com/logout?redir=about.html .

Now, after logging the user, check if $_GET['redir'] exists, and if it does, send them back to that page, other send them to the homepage. After logging out, and before redirecting to the same page, it might be a good idea to show them another page for a few seconds that says 'You've been logged out.'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM