Streamline EventServiceProvider
into RequestLoggerServiceProvider
#39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
EventServiceProvider
(which extendedIlluminate\Foundation\Support\Providers\EventServiceProvider
) in this package gave my a huge headache: The framework'sRegister
event was always triggered twice because of this double registration inEventServiceProvider
:On any user registration, the
SendEmailVerificationNotification
listener got triggered twice and the user effectively got two verification emails.I stepped into this problem previously on my own package
onlime/laravel-http-client-global-logger
where @pascalbaljet and I fixed it in v1.1.3 by ditching the wholeEventServiceProvider
.This bug is extremely hard to track down if you're not into the framework. Even the
debug_backtrace()
ofSendEmailVerificationNotification
would lead to the same backtrace, and theRegister
event only gets dispatched in Laravel'sRegisteredUserController
.The problem only seems to occur since Laravel 11, related to the introduced Email Verification Notification on Registration
SendEmailVerificationNotification
auto-registration.Possibly related issues of others struggling with it:
SendEmailVerificationNotification
gets invoked multiple times laravel/framework#50783So, in this PR I have just streamlined
EventServiceProvider
intoRequestLoggerServiceProvider
by this simple listener registration:Event::listen(RequestHandled::class, LogRequest::class);
which fixes all the negative side-effects of duplicate
EventServiceProvider
registration.