Laravel 5 Event Handler Not Firing

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',
    ],
];

Don't be like me and cache your events locally to test something, then forget to clear that cache 😅

php artisan event:clear

If you run php artisan optimize, your event handlers should start listening.

Credit to mattstauffer from the larachat slack channel for that one.


I ran

composer dumpautoload

followed by

php artisan clear-compiled

Then my events began firing.