Search code examples
phplaravellaravel-5laravel-5.4laravel-5.5

Receiving a wrong reset password link in Laravel 5.5


I'am using php artisan make:auth in my project, everything work perfectly except the sent link to reset passwords. The link didn't contain the correct url, the project name is missed. This is the link sent before I proceed to the notification solution: http://localhost/password/reset/05929a8e465ddfa123a4c068da455cf63c3b9b90ec500a0e1045f092bbd0d97a I have create this Method in my User class :

public function sendPasswordResetNotification($token) {
    $this->notify(new ResetPasswordNotification($token));
}

and then I have created a notification class that contain toMail method to override the existing one in \vendor\laravel\framework\src\Illuminate\Auth\Notifications\ResetPassword.php:

class ResetPasswordNotification extends Notification {
use Queueable;
...
...
    public function toMail($notifiable) {
    return (new MailMessage)
        ->line('You are receiving this email because we received a password reset request for your account.')
        ->action('Reset Password', route('password.reset', $this->token))
        ->line('If you did not request a password reset, no further action is required.');
}

The link I got now worked as expected, and this is the sent link: http://localhost/myproject/public/password/reset/435e453cfa30c968c96ded21c964d70e21459d6ae6ffae8f4972c229773e8a6a. but, I don't know if I change toMail method in ResetPassword.php directly instead of doing it by notification will cause any problems in Production or something else, I will change only ->action part.

Thank's a lot.


Solution

  • In Laravel 5.5, the built in notification builds the url with this code:

    url(config('app.url').route('password.reset', $this->token, false)))
    

    The value of config('app.url') can be changed by setting the APP_URL variable in your .env file. If you set the APP_URL value, you do not need to go through the trouble of overriding the built in functionality.

    APP_URL=http://localhost/myproject/public