I am currently facing an issue with duplicate listeners for my PodcastProcessed event in my Laravel application. I have two listeners: SendPodcastNotification and SendPodcastNotification1. However, when I run the command php artisan event:list, I see that both listeners are being listed as duplicates.
Here is my implementation:
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Event::listen(PodcastProcessed::class , [SendPodcastNotification1::class , 'handle']);
Event::listen(PodcastProcessed::class , [SendPodcastNotification::class , 'handle']);
}
Event discovery is enabled by default; so you are getting the auto-discovered event/listeners as well as your explicitly defined ones.
You could turn off event discovery, but it will then be turned off for all events which might be undesirable. The alternative is to remove the type-hints on the handle method parameters so discovery does not work for those listeners:
- public function handle(PodcastProcessed $event): void
+ public function handle($event): void