代码之家  ›  专栏  ›  技术社区  ›  eComEvo

将Laravel作业链接到通知

  •  0
  • eComEvo  · 技术社区  · 5 年前

    假设我想在成功发送通知后写日志。我希望它能起作用,但它在通知以下内容后从未执行链中的作业:

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

    不会触发任何错误。

    我怎样才能让它工作?

    0 回复  |  直到 5 年前
        1
  •  1
  •   Ricardinho    5 年前

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

    您可以在EventServiceProvider中注册此事件的侦听器,如laravels文档所示: https://laravel.com/docs/8.x/notifications#notification-events

    下面是一个例子: Laravel Notifications Listener Is Useless When Implementing the Queue