Laravel 5.3 Redefine "reset email" blade template

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.
}

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

Tags:

Laravel 5.3