jeudi 19 juillet 2018

Laravel - How to access $notifiable from within email template

Laravel 5.5 app: I decided to customize my mail templates, so I ran the following artisan commands:

artisan publish:vendor --tag=laravel-mail
artisan publish:vendor --tag=laravel-notifications

Then I decided to edit the copyright info at the bottom of resources/views/vendor/mail/html/message.blade.php so I could add some links beneath that, but in order to generate those links, I need access to the $notifiable entity. Only problem is, I can't find any way to access it from within the template. I would prefer not to have to pass $notifiable to a view each and every time I send an email. But, even if I pass $notifiable to the view from the notification's toMail() method, like so:

return (new MailMessage)
    ->subject('Verify Email')
    ->markdown('mail.email-verification-email', [
        'notifiable' => $notifiable
    ]);

I still can't access it from the file mentioned above. It throws an error unless I check if the variable is set, and it never is.

I stumbled across this answer here on Stack Overflow, but I don't understand how the answer solves the issue. I think the answer is addressing a slightly different issue.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire