Skip to content

[5.8] Bug Fix: Render MailMessage if view method was used#29698

Merged
taylorotwell merged 1 commit intolaravel:5.8from
muhammetsait:patch-1
Aug 23, 2019
Merged

[5.8] Bug Fix: Render MailMessage if view method was used#29698
taylorotwell merged 1 commit intolaravel:5.8from
muhammetsait:patch-1

Conversation

@muhammetsait
Copy link
Copy Markdown
Contributor

MailMessage supports customizing its contents by setting lines of text or by using the view method to specify a custom template.

However, if you call view on MailMessage it will fail when calling render.

Steps to reproduce:

  • Create a notification php artisan make:notification InvoicePaid.

  • In the method toMail: return a new MailMessage with a custom view:

    public function toMail($notifiable)
    {
        return (new MailMessage)->view(
            'emails.name', ['invoice' => $this->invoice]
        );
    }
  • Add code to preview that notification:

    Route::get('mail', function () {
        $invoice = App\Invoice::find(1);
    
        return (new App\Notifications\InvoicePaid($invoice))
                    ->toMail($invoice->user);
    });

It will result in the following error: InvalidArgumentException View [] not found.

All code snippets were taken from https://laravel.com/docs/5.8/notifications
Specifically, formatting-mail-messages and previewing-mail-notifications sections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants