Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change password reset redirect link in Laravel 5

I am following this tutorial on setting up authentication with Laravel and I am mostly there apart from one bit.

When I make a request for a password reset I get an email sent out to me and if I click on the link in the email I get to a form which I then fill in correctly and expect to be redirected back to /dashboard, however this never happens and instead it redirects to /home.

I can't provide any code as everything is done behind the scenes by Laravel. Any help appreciated : ).

like image 284
Petar Vasilev Avatar asked Oct 27 '15 12:10

Petar Vasilev


1 Answers

This is because you are expecting the reset password controller to redirect you to /dashboard on a successful reset. Maybe I'm wrong, but I can't see anywhere in the code where that is specified (based, as you say, on a fresh Laravel install).

To demonstrate this, let's follow the code:

By default in a fresh Laravel installation you get a PasswordController in your app/Http/Controllers/Auth/ directory. On line 21 of that file, it 'includes' the ResetsPasswords trait. So let's look at that trait.

As you can see, in the postReset method (which is the method that is run to do the final actual password reset), on line 95 the redirect location is deferred to redirectPath, and as you can see, on line 131 the code specifically forwards the user to /home if no redirectPath or redirectTo property exists on the controller.

So, to manually set the redirect location, just set protected $redirectPath = '/dashboard'; in your Http\Controllers\Auth\PasswordController class.

But also, on the page you linked to, see the section "After resetting passwords" for the official docs on this.

like image 101
alexrussell Avatar answered Sep 30 '22 06:09

alexrussell