[12.x] Add support for named arguments in event dispatching and broadcasting#58913
Merged
taylorotwell merged 1 commit intoFeb 19, 2026
Merged
Conversation
Contributor
|
Warning Named ArgumentsNamed arguments are not covered by Laravel's backwards compatibility guidelines. We may choose to rename function arguments when necessary in order to improve the Laravel codebase. Therefore, using named arguments when calling Laravel methods should be done cautiously and with the understanding that the parameter names may change in the future. |
Contributor
|
@shaedrich Isn't that warning about named arguments in Laravel's own code? This feature allows you to use named arguments when dispatching your own events (thus your own named arguments, not Laravel's). |
Contributor
|
Oh, okay—sorry, nevermind 😬 |
This was referenced Mar 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary:
The
Illuminate\Foundation\Events\Dispatchabletrait currently usesfunc_get_args()indispatch()andbroadcast().That pattern does not support named arguments in PHP.
At the same time, other
dispatchableentry points in the framework already support named arguments (especially in jobs). This PR aligns event dispatching with that existing developer experience.Before:
After:
Benefits
Core framework changes:
dispatchandbroadcaststatic methods in theDispatchabletrait to accept variadic arguments, enabling support for named arguments when instantiating event classes. [1] [2]Testing improvements:
EventsDispatcherTest.phpandBroadcastedEventsTest.phpto verify that events can be dispatched and broadcasted using named arguments, ensuring correct instantiation and argument mapping. [1] [2]DispatchableNamedArgumentsEventandBroadcastableNamedArgumentsEventtest classes to validate named argument support in event dispatching and broadcasting. [1] [2]PendingBroadcastin the test suite.