phplaravellaravel-8forgot-password

Add email next to token in Laravel forgot password template email link


I'm using Laravel 8.5 with authentication system. When user wants to change password it sends an email with link. Default email contains link which looks like this:

http://mywebsite/api/forgot-password?token=2ccece360b031db4dcadea0cbdf8dd47a1712632b727487a7226f19f8f607cc7&email=MyEmail%40gmail.com

I did some changes in email template. In ResetPasswordNotification.php I added this:

public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->subject('MyApp password reset')
                    ->line('You are receiving this email because we received a password reset request for your account.')
                    ->action('Reset Password', $this->url)
                    ->line('This password reset link will expire in 60 minutes.')                    
                    ->line('If you did not request a password reset, no further action is required.');
    }

and in User.php I have:

public function sendPasswordResetNotification($token)
    {    
        $url = 'http://mywebsite/en/change-password?token=' . $token;    
        $this->notify(new ResetPasswordNotification($url));
    }

and now I receive this link:

http://mywebsite/en/change-password?token=8f87fc2d504507as385b4c47cb015cee4192749d3f1d641863524d513abb2a39

which only contains token and not email. How do I add email to this so it would look something like this:

http://mywebsite/en/change-password?token=8f87fc2d504507as385b4c47cb015cee4192749d3f1d641863524d513abb2a39&email=UserEmail@gmail.com

Solution

  • Just add $this->email next to $token.

    public function sendPasswordResetNotification($token)
    {    
        $url = 'http://mywebsite/en/change-password?token=' . $token . '&email=' . $this->email;    
        $this->notify(new ResetPasswordNotification($url));
    }