So I\'m trying out the new Laravel 5 Event methodology.
In my repository, I\'m firing the event \"KitchenStored\" as so:
// Events
use App\\Events\\
This is an older question, but I came across this same issue and for me, it was because I'd added my new Event to the service provider but crucially I had not imported it. For anyone in 2020 with this issue, check that you have imported the event.
If you run php artisan optimize
, your event handlers should start listening.
Credit to mattstauffer from the larachat slack channel for that one.
In EventServiceProvider.php
, include the leading \
when referencing a class using the ::class
notation:
protected $listener = [
\App\Events\KitchenStored::class => [
\App\Handlers\Events\AttachCurrentUserToKitchen::class,
],
];
You could also add use
statements and keep your listener mappings short:
use App\Events\KitchenStored;
use App\Handlers\Events\AttachCurrentUserToKitchen;
...
protected $listener = [
KitchenStored::class => [
AttachCurrentUserToKitchen:class,
],
];
Or just use the string notation:
protected $listener = [
'App\Events\KitchenStored' => [
'App\Handlers\Events\AttachCurrentUserToKitchen',
],
];
I ran
composer dumpautoload
followed by
php artisan clear-compiled
Then my events began firing.
I had a similar issue and I fixed it by deleting the vendor\compiled.php file. Then I run "composer update" again and now the handler is firing as expected.
Don't be like me and cache your events locally to test something, then forget to clear that cache