【问题标题】:Chaining a Laravel job to a notification将 Laravel 作业链接到通知
【发布时间】:2021-01-21 12:29:15
【问题描述】:

假设我想在成功发送通知后写日志。我希望这可以工作,但在通知后它永远不会执行链中的工作:

$user->notify((new SendSomeEmail($content))->chain([
    new LogEmail($user, $content)
]));

不会触发任何错误。

如何让它工作?

【问题讨论】:

  • 你试过 php artisan queue:work 命令了吗?
  • 通知和链式作业都在sync 队列中,因此它们都应该立即运行。

标签: laravel laravel-8


【解决方案1】:

https://github.com/illuminate/notifications/blob/master/RoutesNotifications.php 如你所见,notify 方法返回 void。我认为这就是为什么没有触发“链”方法的原因

你可以做的是在你的 EventServiceProvider 中为这个事件注册监听器,就像 laravel 文档说的: https://laravel.com/docs/8.x/notifications#notification-events

这里有一个例子如何做到这一点: Laravel Notifications Listener Is Useless When Implementing the Queue

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-03
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多