No longer possible to programatically subscribe to events #58126
Replies: 4 comments
-
|
The root problem is that the class which handles discovering event listeners doesn't handle subscribers with the interface-less You have two options to work around this issue:
Either way, the documentation could use some improvement in this area; as is, the subscriber example is pretty much invalidated by event discovery. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @mbabker, thanks for your response. Could you please point me to the documentation that covers disabling event discovery as I am unable to find it for Laravel 11.x / 12.x? It does seem this particular documentation is no longer valid since the Laravel 11.x / 12.x changes, as the methods begin with handle... therefore the subscribe function as per the documentation is completely useless? |
Beta Was this translation helpful? Give feedback.
-
It's not documented from what I could find, but it looks like you should be able to call
Exactly as documented, it isn't helpful. If the method names on the subscriber class were changed to use a prefix other than |
Beta Was this translation helpful? Give feedback.
-
|
@crynobone Could you please explain why this was converted to a discussion when it seems functionality was removed without explaination during the 10.x -> 11.x upgrades and also the example in the documentation is invalid. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Laravel Version
11.x / 12.x
PHP Version
8.3.27
Database Driver & Version
Postgres
Description
In Laravel 10 and below it was possible to programatically subscribe to events like so:
In Laravel 11 and 12 the listeners are fired regardless of the
config('app.env') === 'production'check.Steps To Reproduce
Copy example code from: https://laravel.com/docs/12.x/events#writing-event-subscribers.
Wrap the
$events->listencalls in thesubscribemethod in any check even theif (false) {}.Observe listeners are still fired.
Beta Was this translation helpful? Give feedback.
All reactions