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;
app/Providers/AppServiceProvider.php
1
public function boot()
2
{
3
$this->loadViewsFrom(resource_path('views/mail'), 'appmail');
4
}
5
Copied!
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;
1
public function toMail($notifiable)
2
{
3
return (new MailMessage)
4
->theme('appmail::mycorp')
5
->subject('Password Reset')
6
->line('Your password reset code is specified below')
7
8
// etc
Copied!
Last modified 1yr ago
Copy link