[5.8] Fix incorrect event namespace in generated listener. #28007
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.
Problem Summary
See #27468
The issue arises when running
event:generate
for events in third-party namespaces (non-App and non-Illuminate).The FQCN of the event (in the "use" statement at the top of the Listener class) has a preceding '\'.
Before
After
Details
In
ListenerMakeCommand
, there is a check to see if the given event namespace starts with:(1) your project namespace(App)
(2)"Illuminate"
(3)"\"
So it looks like the
event:generate
command expects 3 situations:If those assumptions are true, then you should be able to generate listeners from events in third party namespaces by adding a starting '\' to your event in the
$listen
array of your EventServiceProvider.However, if you do that, then the '\' doesn't get dropped and the namespace at the top of the generated listener for your event, will still have the starting '\'.
Solution
Simply
trim
the full event name when replacing theDummyFullEvent
.