作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将变量传递给我的通知标记(而不是直接通过通知 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/
我是一名优秀的程序员,十分优秀!