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.
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.
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.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With