Nauman Zafar
Nauman Zafar

Reputation: 1103

Event Handler not receiving event Laravel

I am with L5.4 working on notification system. I have created events & listeners. I do have a test route for firing this event. Event is fired successfully and I can even recieve it using Pusher in my blade views.

But for some reason I have to stop within handle(NewUser $event) method of my listener. I tried dd($event) But it never stops there. Although I have registered events and listeners mapping within my EventServiceProvider with listen property

//App/Providers/EventServiceProvider.php
 protected $listen = [
        'App\Events\NewUser' => [
            'App\Listeners\NewUserAdminNotification',
        ],
    ];

Actually, I want to store a notification in my database within that handle method of listener. But It never enters that method.

Any pointer to the problems are highly appreciated.

Upvotes: 3

Views: 1349

Answers (2)

Nauman Zafar
Nauman Zafar

Reputation: 1103

Changing the notation for events & listeners classes works for me.

//App/Providers/EventServiceProvider.php

 protected $listen = [
        \App\Events\NewUser::class => [
            \App\Listeners\NewUserAdminNotification::class,
        ],
    ];

Upvotes: 0

Jono20201
Jono20201

Reputation: 3205

Sometimes you need to clear the compiled classes to get Laravel to register the new events.

In console/terminal run:

composer dump-autoload

and

php artisan clear-compiled

Upvotes: 0

Related Questions