Closure listeners are defined with a closure alone, no need to have MessageSending::class as first parameter:
Event::listen(function (MessageSending $event) {
$tracker = new MailTracker;
$tracker->messageSending($event);
});
Are you suggesting his code does not work? Because it does (if I remove my listener).
Sorry, my suggestion was wrong, I misread your post.
What php artisan event:list shows? Do you see both listeners for MessageSending event there?
App\Events\TestEvent ...........................
⇂ Closure at: /app/Providers/AppServiceProvider.php:111
⇂ App\Jobs\TestJob (ShouldQueue)
⇂ App\Actions\TestAction
⇂ App\Jobs\TestJobNew (ShouldQueue)
I see 2 handlers for Illuminate\Mail\Events\MessageSending, yet only 1 runs (the first one)
The 1st one is a class, 2nd is a closure.
How do you know the second listener is not run?
What if you apply your own test closure (with simple Log::debug('test listener');) as third listener - will it run and write to log?
Did you run php artisan optimize:clear or event:clear to flush events cache?
Because I step debug and also there are no tracked links in the email (second listener's job)
@laracoft You can define multiple listeners for an event by passing an array as the second parameter:
Event::listen(MessageSending::class, [
ListenerOne::class,
ListenerTwo::class,
]);
Thanks, but the docs say I can call it multiple times, and it doesn't work as described in my case. (I can't call an array because it is 2 separate service providers)
After more debugging, I found the issue: for a handler's handle(), it must return null. Anything else will cause the next handler not to run.
Please sign in or create an account to participate in this conversation.