Hans M.
Hans M.

Reputation: 79

Laravel 5.6 - how to change theme of notification

I send out user emails and afterwards an admin report. I want to change the theme of the admin notification.

To do this I defined a custom css template in the vendor/mail/themes directory.

I tried to follow this example although it is for Mailables:

https://laravel-news.com/email-themes

class AdminReport extends Notification
{
use Queueable;
protected $theme = 'adminemail';

But this doesn't change anything the theme.

I also tried to change the theme before the notification is sent and it didn't work:

 config([ "mail.markdown.theme" => "adminemail" ]);

Changing the theme does work though when I set the config before I send out the first user notification.

Does anyone know the right way to do this?

Upvotes: 2

Views: 1508

Answers (1)

Propaganistas
Propaganistas

Reputation: 1792

As of Laravel v5.3.7 Mailables can also be passed to Notifications. So create a Mailable for your email and then pass the mailable to the toMail() method:

class AdminReport extends Mailable
{
    protected $theme = 'my-theme';

    ...
}

-

class AdminReport extends Notification
{
    ...

    public function toMail($notifiable)
    {
        return (new App\Mailables\AdminReport)->to($notifiable->email);
    }
}

Upvotes: 1

Related Questions