Back

Changing the redirect for a successful login


Alright, I know this might seem trivial and hopefully I just missed it...

I am using the out of the box Auth in Laravel 5. I have everything working fine as expected minus one issue...

I am using a modal to log a user in, after a successful login - the user is redirected to /home which does not exist anymore...

That being said, where can I change the redirect for successful authentication?

goedda replied 4 years ago Solution

Well, the 'redirectPath()' method will first check for a property called 'redirectTo' and if not found, it will redirect to \home. That being said, you could naturally hack the core controller method, but I would not recommend it. Better to follow the guideline ;)

Check out that link (Chapter 'Password Reminders & Reset > Password Reminder Controller) http://laravel.com/docs/master/authentication

i.e. open Root/app/Http/Controllers/Auth/PasswordController.php and add the respective variable

protected $redirectTo = '/xy';

That should help.

Jason McCallister replied 4 years ago

I really don't know what I was thinking when I wrote that... but that was somewhat the solution, with one exception.

On my Auth\AuthController I simple needed to set the property:

protected $redirectPath = '/';

The AuthenticatesAndRegistersUsers trait has a method redirectPath that checks if that property exists. If that property is absent it will redirect to /home.

Thanks again!

goedda replied 4 years ago

Sorry for the confusion. But you got the idea.


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us