Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset Password Email

I am new to laravel development and currently working on small project. I would like to customize the email template for the reset passwords or even link it to completely different template. For the authentication scaffolding I have used the php artisan make:auth command.

However the default reset password functionality uses default laravel email template. Is it possible that I can create different email template and link it to reset password Controller? Also I would like to pass in additional user information in.

I am using laravel 5.4 version.

like image 699
Martin Kiss Avatar asked Oct 30 '22 09:10

Martin Kiss


1 Answers

You can generate a Notification class with:

php artisan make:notification ResetPassword

You can override toMail() method there to customize subject and line.

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

And in users model:

   use Illuminate\Notifications\Notifiable;
   use App\Notifications\ResetPassword as ResetPasswordNotification;

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

And to customize whole email template. here is the view: resources/views/notification/email.blade.php;

And in config/app.php, You can change the application name, default is laravel.

like image 91
Sanzeeb Aryal Avatar answered Nov 09 '22 15:11

Sanzeeb Aryal