Laravel: How to avoid redirecting to home after login?

If you are working on a Laravel 5.1 based project and using Auth class for authentication purpose, chances are you would have faced issue of redirecting to home after login.

While docs say that you can override the behaviour by setting the $redirectedPath value. Thing is it will still not work. After wasting a reasonable time, I figured out the issue.

By default Auth constructor is defined as:

 

This middleware actually calls  RedirectIfAuthenticated trait. If you go to definition you will find:

 

Hardcoded right. So the best is to omit out the following line from constructor:

Add following protected method to override default redirection:

 

And it should work then.

2 responses to “Laravel: How to avoid redirecting to home after login?”

  1. Akinola says:

    Thanks for this tip. I spent the last 2 hours on this issue.

  2. irwan_up says:

    Thanks a lot, I’ll try this. Hope your solution work for me. I’ve been wasting 2 days to figure this out and nothing works. It really drives me mad.

Leave a Reply

Your email address will not be published. Required fields are marked *