Specify a different mail theme for Notifications

Where to place a custom mail theme in Laravel

This issue was resolved in Laravel 8.5 https://github.com/laravel/framework/issues/34391

Views can use something called Hints to tell the framework where to look for the view file. The theme always uses a hint of Mail:: which corresponds to the resources/views/vendor/mail/html folder. What if we want to locate our theme somewhere else?

We can define our own hint and bind it into the system in the AppServiceProvider with;

    public function boot()
        $this->loadViewsFrom(resource_path('views/mail'), 'appmail');

With this, we are saying that any view file that is hinted with appmail:: is found in the views/mail folder.

Then, in the Notification, add the hint in the theme function;

  public function toMail($notifiable)
    return (new MailMessage)
      ->subject('Password Reset')
      ->line('Your password reset code is specified below')
    // etc

Last updated