eComEvo
eComEvo

Reputation: 12589

Chaining a Laravel job to a notification

Suppose to I want to write a log after a notification is successfully sent. I'd expect this to work, but it never executes the job in the chain after notifying:

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

No errors are triggered.

How do I get this to work?

Upvotes: 1

Views: 949

Answers (1)

Ricardinho
Ricardinho

Reputation: 609

https://github.com/illuminate/notifications/blob/master/RoutesNotifications.php as you can see, notify method returns void. I think that's why 'chain' method is not being triggered

What you can do is register listeners for this event in your EventServiceProvider like laravels document says: https://laravel.com/docs/8.x/notifications#notification-events

here there is an example how to do this: Laravel Notifications Listener Is Useless When Implementing the Queue

Upvotes: 1

Related Questions