[英]Laravel: skip via database notification
I am trying to send the explicit via Email
only using the notification class where it is configured for both ['mail', 'database']
我正在尝试仅使用为
['mail', 'database']
配置的通知类通过Email
发送显式
Notification::route('mail', $shopadmin->email)->notify(new ShopadminCreated($model));
But it still goes into toArray()
method and generates error.但它仍然进入
toArray()
方法并产生错误。
The reason is, I am using the same class to renotify using email but this time no database entry need to be created.原因是,我使用相同的类来使用电子邮件重新通知,但这次不需要创建数据库条目。
Solution:
解决方案:
After stumbling upon the Documentation on Notification.在偶然发现通知文档之后。 I tried this block of code and implement with below modification:
我尝试了这段代码并通过以下修改实现:
ShopadminCreated.php: ShopadminCreated.php:
...
public function via($notifiable)
{
return $notifiable->prefers_email ? ['mail'] : ['mail', 'database'];
//return ['mail', 'database'];
}
...
Controller:控制器:
$data = $notification->data; // Array fetched from database
$model = Admin::hydrate([$data])[0];
$model->setAttribute('prefers_email', true);
Notification::send($shopadmin, new ShopadminCreated($model));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.