如何通过手动更改Laravel 5.4通知
如何在控制器中设置通孔 如果一个用户想要邮件通知,而第二个用户不想要邮件通知如何通过手动更改Laravel 5.4通知,laravel,laravel-5.4,Laravel,Laravel 5.4,如何在控制器中设置通孔 如果一个用户想要邮件通知,而第二个用户不想要邮件通知 那么,如何设置一个用户通知通过邮件发送,第二个用户通知不通过邮件发送 $newinvoice = New NewInvoice('create a new invoice',$invoice->id); $newinvoice->via(['database','broadcast','mail']); Notification::send($sendToUser, $newinvoice); 当我运
那么,如何设置一个用户通知通过邮件发送,第二个用户通知不通过邮件发送
$newinvoice = New NewInvoice('create a new invoice',$invoice->id);
$newinvoice->via(['database','broadcast','mail']);
Notification::send($sendToUser, $newinvoice);
当我运行这个代码时,给我一个错误
InvalidArgumentException in Manager.php line 90: Driver [1] not supported.
提前感谢您可以将频道作为另一个参数提供给通知构造函数
$newinvoice = New NewInvoice('create a new invoice',$invoice->id, 'mail');
您还可以提供一组通道
$newinvoice = New NewInvoice('create a new invoice',$invoice->id, ['mail', 'broadcast']);
在您的notifiable类别中创建属性
protected $_channel = null;
构造函数可以将通道保存到此属性
public function __construct($description, $invoiceId, $notificationChannel)
{
$this->_channel = $notificationChannel;
}
您的via()方法可以执行以下操作
public function via($notifiable)
{
if (!$this->_channel)
{
throw new \Exception('Sending a message failed. No channel provided.');
}
return is_array($this->_channel) ? $this->_channel : [$this->_channel];
}