我正在尝试将变量传递到我的通知标记语言中(而不是直接通过通知的toMail
方法),因为我需要多个操作按钮。我希望用户能够回答电子邮件中提出的问题。以下是我在通知标记语言中尝试的内容:
@component('mail::button', ['url' => 'https://myapp.dev/response/' . $event->id . '/' . $user->id . '/yes'])
Yes
@endcomponent
@component('mail::button', ['url' => 'https://myapp.dev/response/' . $event->id . '/' . $user->id . '/no'])
No
@endcomponent
以下是通知本身的代码:
class eventAlert extends Notification
{
use Queueable;
public $event;
public $user;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Event $event, User $user)
{
$this->event = $event;
$this->user = $user;
}
public function toMail($notifiable)
{
return (new MailMessage)
->greeting('Hey ' . $this->user->fn)
->line('There is an event today @ '. $this->event->edatetime->format('h:i A'))
->line($this->event->location)
->markdown('mail.notifications.eventalert');
}
但是,我尝试运行计划任务时遇到一个错误,即事件变量未定义。我知道对于Mailable
类,您可以在标记中使用通过构造函数传递的数据,因此我尝试将我的变量从protected
更改为public
,就像Mailable
类所需的那样,但这仍然不起作用。如何将我的变量数据传递到通知标记中?
$event
对象? - Chinonso Chukwuogor$event->id
这样的数据添加到markdown中。是的,在Job的handle方法中,$user->notify(new eventAlert($event, $user));
。 - develpr