Try
public function toMail($notifiable,$data)
{
return (new MailMessage)->subject('Invoice Paid')->markdown('mail.new_job.user_notification', ['data' => $data]);
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am struggling with passing variables to a markdown template from the notification. My Notification Class:
use Queueable;
public $data;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($data)
{
$this->data = $data;
//$this->onQueue('jobs_status');
//$this->delay(Carbon::now()->addSeconds(35));
}
/**
* 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 \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)->subject('Invoice Paid')->markdown('mail.new_job.user_notification', ['data' => $data]);
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
My markdown template:
@component('mail::message')
# Introduction
{{ $data }}
@component('mail::button', ['url' => $url])
@endcomponent
Thanks,<br>
{{ config('app.name') }}
@endcomponent
This code throws an error : Undefined variable: data.
Do you know the correct way to pass variable to the markdown template?
Thank you in advance for any help!
Please or to participate in this conversation.