So i came across a situation where i wanted to access the listeners array of \App\Providers\EventServiceProvider, and here’s what i did.
I didn’t just need to print the php artisan event:list, i needed to compare that list with some value i had. Apparently there was a way to access a provider using the app()->getProvider()
command, and the code was:
app()->getProviders(EventServiceProvider::class);
That syntax will return an array of providers, you can either foreach that or make it into a collection and return the first value
# Example 1
foreach(app()->getProviders(EventServiceProvider::class) as $_provider);
# Example 2
collect(app()->getProviders(EventServiceProvider::class))->first();
Both work however i didn’t need to loop through that, i only needed the first one, so i went for Example 2.
Now to access the listeners simply use the listens() method inside the provider;
$Listeners = collect(app()->getProviders(EventServiceProvider::class))
->first() # The first item in collection
->listens() # Listens(), belongs to getProviders() method.
That’s it, i hope you find that useful.