Display Laravel Notification (MailMessage) with markdown after sent

I’m saving every email I send to an entity into the database by creating a function storeEmail and make an insert of MailMessage class into EmailMessage model. Everything works fine, and the main goal is to display the message exactly as it was, when the recipient received it and retrieve all the messages I sent as a User, to a page. To be much easier to retrieve a render of each specific Message in foreach loop, I think is better to fetch it from the Model.

This is my Notification class:

class SimpleEmail extends Notification
use Queueable;

private $link;
private $user;

* Create a new notification instance.
* @return void
public function __construct($link)
$this->link = $link;
$this->user = Auth::user();

* Get the notification's delivery channels.
* @param mixed $notifiable
* @return array
public function via($notifiable)
return ['mail'];

* Get the mail representation of the notification.
* @param mixed $notifiable
* @return IlluminateNotificationsMessagesMailMessage
public function toMail($notifiable)
$mail = (new MailMessage)
->from($this->user->email, $this->user->name)
->subject('My Dummy Subject')
->greeting('To: '.$notifiable->email)
->action('Action Button', url($this->link))
->line('Thank you for reading my message')
->salutation('Friendly, '.$this->user->name);

return $mail;

public function storeEmail($mail,$notifiable){
$email = new EmailMessage;
$email->sender_type = 'AppUser';
$email->sender_id = $this->user->id;
$email->mail = $mail;


  1. I’m using IlluminateNotificationsMessagesMailMessage
  2. My class extends IlluminateNotificationsNotification
  3. I’m saving (new MailMessage) in the $email->mail = $mail;

I tried to dd($email->mail); and I get this:

 ^ array:20 [▼
"view" => null
"viewData" => []
"markdown" => "notifications::email"
"theme" => null
"from" => array:2 [▶]
"replyTo" => []
"cc" => []
"bcc" => []
"attachments" => []
"rawAttachments" => []
"priority" => null
"callbacks" => []
"level" => "info"
"subject" => "My Dummy Subject"
"greeting" => "To: Dohn John"
"salutation" => "Friendly, Nikolas Diakosavvas"
"introLines" => array:2 [▶]
"outroLines" => array:1 [▶]
"actionText" => "Action Button"
"actionUrl" => "http://my-example-url.com ▶"

How can I display the Mail Notification, as it was when I sent it ? What is the optimal solution for that ? Thanks, in advance


Managed to render MailMessage using this code works :

$email = EmailMessage::first();
return (new AppNotificationsSimpleEmail('my-link', $email->recipient->assignto))->toMail($email->recipient);

But this is not exactly what I wanted, because every time I need to find:

  1. Which Notification class used on every email so I can render it.
  2. Variables for each Notification class.

from Newest questions tagged laravel-5 – Stack Overflow https://ift.tt/37A5Hw3

Related Posts

Codeigniter : Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE) in Laravel project

I’m getting following error: **Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE)** Note : It’s working in local but facing issue in production server. private…

Firebase receive notification while tab is active or on focus

What i want is to be able to perform an action when a user receives a notification while the browser is open and tab is active or…

Laravel’s alias loader does not find class

We have a legacy project that we cannot update and we need to make some changes in symfony’s Response.php in vendor. We have solved this by copying…

Laravel 5 – generic document management

I have a system where you can create different types of unique documents. For instance, one document is called Project Identified and this expects certain inputs. Originally,…

Laravel Nova limit the results in indexQuery

I ran intro a situation where I need to limit the results of a resource to only 3 results. To be more specific, based on the logged…

Auditoria en laravel 5.8 [closed]

Cómo puedo automatizar el registro de actividades de un usuario en laravel? Si un usuario ingresa a un app de laravel, debo guardar toda su actividas, a…

Leave a Reply

Your email address will not be published.