使用 Laravel 5.3,我可以在 Notification
中定义收件人:
// In a class extending Illuminate\Notifications\Notification :
public function toMail($notifiable)
{
return (new MailMessage)->line('hello')->to('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3b565e7b5e435a564b575e15585456" rel="noreferrer noopener nofollow">[email protected]</a>');
}
自 Laravel 5.4 ( relevant commit ) 起,我无法使用 to
。我如何更新我的代码?我需要向未绑定(bind)到用户或对象的电子邮件发送通知。如何“破解”这些缺失的功能?
最佳答案
创建一个带有电子邮件属性的最小类:
class MyNotifiable
{
use \Illuminate\Notifications\Notifiable;
public $email;
public function __construct($email)
{
$this->email = $email;
}
}
然后在您的最小类上调用notify
:
(new MyNotifiable('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="deb3bb9ebba6bfb3aeb2bbf0b1acb9" rel="noreferrer noopener nofollow">[email protected]</a>'))->notify(new MyNotification);
而且它有效。
关于php - Laravel 邮件通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42087782/