为 Laravel 个通知指定队列名称

Specifying queue name for Laravel notifications

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

$user->notify($notification);

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

将作业推送到特定队列
ProcessPodcast::dispatch($podcast)->onQueue('tenant1');

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

由于您的通知应使用 the Illuminate\Bus\Queueable trait you can simply set the $queue property of the object. There's a helper function

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