gpt4 book ai didi

laravel - 如何将数据传递给 Laravel 中的通知 Markdown ?

转载 作者:行者123 更新时间:2023-12-04 15:55:19 25 4
gpt4 key购买 nike

我正在尝试将变量传递给我的通知标记(而不是直接通过通知 toMail 方法),因为我需要多个操作按钮。我希望用户能够回答电子邮件中提出的问题。这是我在通知 Markdown 中尝试的内容:

@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 类,您可以在 markdown 本身中使用通过构造函数传递的数据,因此我尝试将我的变量从 protected 更改为 public > 就像它应该用于 Mailable 类一样,但这仍然不起作用。如何将可变数据传递给通知 Markdown ?

最佳答案

如果将它赋给函数中的变量会发生什么,例如:

public function toMail($notifiable)
{
$aux = $this->event;

return (new MailMessage)
->greeting('Hey ' . $this->user->fn)
->line('There is an event today @ '. $aux->edatetime->format('h:i A'))
->line($aux->location)
->markdown('mail.notifications.eventalert');
}

如果这都不起作用,则可能是事件未正确分配。

关于laravel - 如何将数据传递给 Laravel 中的通知 Markdown ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51955677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com