Repository: owen-it/laravel-auditing

Issue #923: AuditingEventServiceProvider disables Laravel's Event Auto-Discovery
Created: 2024-04-22T16:35:27Z
Q
A




Bug?
yes


New Feature?
no


Framework
Laravel


Framework version
11.4.0


Package version
13.6.5


PHP version
8.3.6



Actual Behaviour
I've already filed an extensive bug report in the laravel/framework repository, which has been rejected. I am not yet 100% convinced that this not at least partly a framework problem.
Once the auditing package is installed, Laravel's event auto-discovery no longer works. This means that events and listeners from my application will not be detected. I (want to) rely on auto-discovery.
I am pretty sure this is caused by the AuditingEventServiceProvider inheriting from the framework's base EventServiceProvider.
I have found that the framework's EventServiceProvider is no longer registered once another service provider inheriting from that base class is registered. This is the case for your service provider. I am still trying to figure out how the framework works and registers those service providers.
As the auditing service provider is registered instead the framework's service provider, this check in shouldDiscoverEvents will return false.
Expected Behaviour
Using your package, Laravel's EventServiceProvider is still registered and event auto-discovery works as expected.
Steps to Reproduce

Fresh installation: https://laravel.com/docs/11.x/installation#sail-on-macos
Follow setup
./vendor/bin/sail art make:event TestEvent
./vendor/bin/sail art make:listener TestListener
Type hint the event (3) in the listener (4)
./vendor/bin/sail art event:list
./vendor/bin/sail composer require owen-it/laravel-auditing
./vendor/bin/sail art event:list
./vendor/bin/sail composer remove owen-it/laravel-auditing
./vendor/bin/sail art event:list

Check the output of (8) and (10) and you will see that at (8) the event and listener are discovered while at (10) they no longer are.
Please have a look at the code in the original bug report.
Possible Solutions
If this package would rely on Manual Registering Events, i.e. not inheriting and not using the $listen array anymore, but instead using the facade in any of the boot functions, I think the problem could be solved.
On the other hand, I still think this is a bug in the framework.

Duplicate issue #924: Laravel Audit breaks Events Auto Discovery 
Created: 2024-04-27T19:43:25Z
Q
A




Bug?
yes


New Feature?
no


Framework
Laravel


Framework version
11.5.0


Package version
13.6


PHP version
8.2



Actual Behaviour
Laravel's event auto discovery breaks after installing laravel-aduit
Expected Behaviour
Events should still be auto discovered, installing Laravel Audit shouldn't affect that
Steps to Reproduce
you can reproduce this on a fresh laravel project

Create a new Laravel Project

composer create-project laravel/laravel example-app


Create an event

php artisan make:event ProductOrdered


Create a Listener

php artisan make:listener PrintMessage --event=ProductOrdered


Check if the event is discovered or not

sail artisan event:list | grep App 

result: discovred
App\Events\ProductOrdered ..................................................App\Listeners\PrintMessage@handle 


now install laravel-audit

 composer require owen-it/laravel-auditing


Check if the event is discovered or not again

sail artisan event:list | grep App 

result: empty result, event is not discovered

Closing comment (2024-04-29T13:59:23Z): #916
Duplicate of #923