Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 699
rap-2-h Avatar asked Feb 05 '18 10:02

rap-2-h


People also ask

Why are my email notifications not showing up?

First, turn on notifications & choose your settings Tap Notifications and select a notification level. Tap Inbox notifications. Note: If you're using Android O and above, tap Manage notifications. Under your account, make sure the switch is set to On.

How do I turn off email notifications on Windows 10?

Turn alerts on or offSelect File > Options > Mail. Under Message arrival, select or clear the Display a Desktop Alert check box and then select OK.


2 Answers

In your controller's function :

 $message = (new \App\Notifications\MyNotification())->toMail('[email protected]');    
 $markdown = new \Illuminate\Mail\Markdown(view(), config('mail.markdown'));

return $markdown->render('vendor.notifications.email', $message->data());

Just change the name of the notification class (and also pass arguments if necessary) and hit the url in your browser to see the preview.

like image 163
black_belt Avatar answered Sep 26 '22 19:09

black_belt


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);
like image 30
Alexey Mezenin Avatar answered Sep 23 '22 19:09

Alexey Mezenin