Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.3 Redefine "reset email" blade template

Tags:

laravel-5.3

How to customize the path of the reset email blade template in Laravel 5.3?

The template used is: vendor/laravel/framework/src/Illuminate/Notifications/resources/views/email.blade.php

I'd like to build my own.

Also, how to change the text of this email predefined in: vendor/laravel/framework/src/Illuminate/Auth/Notifications/ResetPassword.php

public function toMail()
{
    return (new MailMessage)
        ->line([
            'You are receiving this email because we received a password reset request for your account.',
            'Click the button below to reset your password:',
        ])
        ->action('Reset Password', url('password/reset', $this->token))
        ->line('If you did not request a password reset, no further action is required.');
}
like image 387
Syl Avatar asked Sep 05 '16 09:09

Syl


2 Answers

To change template you should use artisan command php artisan vendor:publish it will create blade templates in your resources/views/vendor directory. To change text of email you should override the sendPasswordResetNotification method on your User model. This is described here https://laravel.com/docs/5.3/passwords in Reset Email Customization section.

You must add new method to your User model.

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

and use your own class for notification instead ResetPasswordNotification.

UPDATED: for @lewis4u request

Step by step instruction:

  1. To create a new Notification class, you must use this command line php artisan make:notification MyResetPassword . It will make a new Notification Class 'MyResetPassword' at app/Notifications directory.

  2. add use App\Notifications\MyResetPassword; to your User model

  3. add new method to your User model.

    public function sendPasswordResetNotification($token)
    {
        $this->notify(new MyResetPassword($token));
    }
    
  4. run php artisan command php artisan vendor:publish --tag=laravel-notifications After running this command, the mail notification templates will be located in the resources/views/vendor/notifications directory.

  5. Edit your MyResetPassword class method toMail() if you want to. It's described here https://laravel.com/docs/5.3/notifications

  6. Edit your email blade template if you want to. It's resources/views/vendor/notifications/email.blade.php

Bonus: Laracast video: https://laracasts.com/series/whats-new-in-laravel-5-3/episodes/9

PS: Thanks @Garric15 for suggestion about php artisan make:notification

like image 70
Eugen Shevchenko Avatar answered Nov 08 '22 22:11

Eugen Shevchenko


I wanted to elaborate on a very helpful Eugen’s answer, but didn’t have enough reputation to leave a comment.

In case you like to have your own directory structure, you don’t have to use Blade templates published to views/vendor/notifications/... When you create a new Notification class and start building your MailMessage class, it has a view() method that you can use to override default views:

/**
 * Get the mail representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \Illuminate\Notifications\Messages\MailMessage
 */
public function toMail($notifiable)
{
    return (new MailMessage)
        ->view('emails.password_reset');
        // resources/views/emails/password_reset.blade.php will be used instead.
}
like image 34
awgv Avatar answered Nov 08 '22 22:11

awgv