【问题标题】:Specifying queue name for Laravel notifications为 Laravel 通知指定队列名称
【发布时间】:2021-01-08 21:34:44
【问题描述】:

我正在构建一个 SAAS,我希望每个租户都有自己的通知队列。我有一个实现Illuminate\Contracts\Queue\ShouldQueue 的通知类,我像这样发送通知

$user->notify($notification);

但我还没有找到一种方法来指定我希望将通知推送到的队列。我知道可以使用onQueue 将作业推送到特定队列:

ProcessPodcast::dispatch($podcast)->onQueue('tenant1');

但是是否也可以对可排队的通知执行类似的操作?

【问题讨论】:

    标签: laravel notifications queue laravel-queue laravel-notification


    【解决方案1】:

    由于您的通知应该使用the Illuminate\Bus\Queueable trait,您可以简单地设置对象的$queue 属性。有a helper function

    $notification->onQueue('tenant1');
    $user->notify($notification);
    

    【讨论】:

    • 太棒了!这很简单。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-11
    • 1970-01-01
    • 2022-08-19
    • 1970-01-01
    • 2020-11-11
    相关资源
    最近更新 更多