【发布时间】:2020-01-26 23:35:12
【问题描述】:
一些用户有另一个电子邮件地址,该地址存储为users 表中的secondary_email 列。
如何使用$user->notify() 向该辅助电子邮件地址发送通知?
【问题讨论】:
一些用户有另一个电子邮件地址,该地址存储为users 表中的secondary_email 列。
如何使用$user->notify() 向该辅助电子邮件地址发送通知?
【问题讨论】:
您将覆盖通知的toMail 方法。例如:
use App\Mail\InvoicePaid as Mailable;
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return Mailable
*/
public function toMail($notifiable)
{
return (new Mailable($this->invoice))
->to($this->user->secondary_email ?? $this->user->email);
}
您可以阅读更多关于格式化通知here。
【讨论】:
您可以在通知实体模型上定义routeNotificationForMail 方法
public function routeNotificationForMail($notification)
{
// Return email address only...
return $this->email_address;
// Return email address and name...
return [$this->email_address => $this->name];
}
然后修改函数以满足您的需要。 laravel documentation notifications
【讨论】: