在 Laravel (5.5) 中使用 Notifications 时,您可以从 toMail()
中访问 Notifiable(收件人)。方法。
当您发送 Mailable 时,是否有等效的方法来访问收件人?
有没有比像这样在构造函数中重复 User 实例更好的解决方案?
Mail::to($user)->send(new EventAlert($user));
最佳答案
不,没有办法。但是您可以在 Notification 类中使用 Mailable 并在 Controller 或服务中使用通知而不是 Mailable 。
来自 the docs :
You may return a mailable object from the
toMail
method
public function toMail($notifiable)
{
return (new Mailable($this->invoice))->to($this->user->email);
}
关于Laravel:从邮件模板中获取电子邮件收件人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48450809/