Laravel 6数据库通知在生产中不起作用

Laravel 6数据库通知在生产中不起作用,laravel,Laravel,我有数据库通知,在本地运行良好。它发送电子邮件以及数据库通知。但是,当我在生产中上传它时,电子邮件(toEmail)发送电子邮件很好,但数据库通知(toDatabase)不起作用。我使用laraval forge部署应用程序。我认为排队工作没有问题,因为电子邮件工作正常 class DBMailNewPaymentAddedgNotification extends Notification implements ShouldQueue { use Queueable; publ

我有数据库通知,在本地运行良好。它发送电子邮件以及数据库通知。但是,当我在生产中上传它时,电子邮件(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 \Illuminate\Notifications\Messages\MailMessage
 */
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\u CONNECTION=database//在本地和生产中都设置为database

这就是我在controller

$users=User::wherePermissionIs('journaux-actions-paiement')->get();
$when=now()->addMinutes(2);
$users->each->notify((new DBMailNewPaymentAddedgNotification($payment))->延迟($when))


您的代码似乎很好,因为它在本地工作,我假设您没有启动您的工作人员

php artisan queue:listen

除此之外,只有
$notifiable->notification\u preference
不包含正确的值。

您应该在via函数中添加数据库

public function via($notifiable)
{
    return ['database'];
}

您是否启动了队列工作程序?是的,同一通知类上的电子邮件正在工作。只是同一类上的数据库通知不起作用。我没有排队就尝试了,但没有成功。那么db中的$notifiable->notification\u首选项是什么?“确定一个空间没有偷偷溜进或类似的地方吗?”@mrhn我感到有点尴尬,但听起来可能是这样。如果这是个问题,我会随时通知你。非常感谢。我写了一个答案,这样我们就可以通过“官方”渠道,而不必在评论部分做所有的事情:)一些关键的事情,你确定吗?足以找到错误:)您是正确的。我在local中手动添加了数据库通知首选项,但我忘记了为生产中的每个用户设置它。你那边的接球很好。非常感谢,伙计。