Search code examples
phplaravellaravel-5laravel-5.5

Preview Mail Notification in browser


With Laravel, according to the documentation, I can return a Mailable via a controller to display it in the browser. It helps to preview mails.

Is there a way to preview Mail Notifications in browser?

I tried:

return (new MyNotification())->toMail($some_user);

But it does not work:

The Response content must be a string or object implementing __toString(), "object" given.


Solution

  • You can't render Notification. You can render Mailable that you use in toMail(). For example if that Mailable is called SomeMailable:

    public function toMail($user)
    {
        return (new SomeMailable($user))->to($user->email);
    }
    

    Then you can render the Mailable with:

    return new SomeMailable($some_user);