我有数据库通知,它在本地运行良好。它发送电子邮件以及数据库通知。但当我在生产中上传它时,电子邮件(toEmail(发送电子邮件很好,但数据库通知(toDatabase(不起作用。我使用laraval forge来部署应用程序。我不认为这是队列工作的问题,因为电子邮件运行良好。
class DBMailNewPaymentAddedgNotification extends Notification implements ShouldQueue
{
use Queueable;
public $payment;
public function __construct($payment)
{
$this->payment = $payment;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return explode(',' ,$notifiable->notification_preference);
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return IlluminateNotificationsMessagesMailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Nouvelle action sur le système.')
->line('Vous recevez cet e-mail car il y a une nouvelle notification dans le système')
->action('Veuillez vous connecter', url('/login'));
}
public function toDatabase()
{
return [
'title' => 'Nouveau paiement soumis',
'category' => 'finance',
'type' => 'added',
'icon' => 'cash',
'note_title' => 'Paiement '.$this->payment->ref_number.' soumis ',
'note_desc' => 'par l'utilisateur '.$this->payment->updatedBy->nom.' '.$this->payment->updatedBy->nom,
'added_by_user_id' => $this->payment->updatedBy->id,
'item_id' => $this->payment->id
];
}
.env QUEUE_CONNECTION=database // Is set to database in local as well as in production
这就是我如何调用控制器
$users = User::wherePermissionIs('journaux-actions-paiement')->get(); $when = now()->addMinutes(2); $users->each->notify((new DBMailNewPaymentAddedgNotification($payment))->delay($when));
中的通知类
您的代码似乎很好,因为它在本地工作,我认为您可能还没有启动您的工作程序。
php artisan queue:listen
除此之外,只能是$notifiable->notification_preference
不包含正确的值。
您应该通过函数添加数据库
public function via($notifiable)
{
return ['database'];
}