Lucas SenCab A Ugh Lucas SenCab A Ugh - 1 month ago 22
PHP Question

How to tie into Illuminate events Laravel 5.3

I want a message on my applications login page when the event of logout is trigged under

vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php
.

Since this is in core I thought it would be as simple as adding:

protected $listen = [
'App\Events\Logout' => [
'App\Listeners\LogoutEvent',
],
];


as stated in https://laravel.com/docs/5.3/events#registering-events-and-listeners

But after running artisan command it just creates a spot for me to make my own event. So my question is, can I listen to core events in Laravel like Logout without creating my own?

Answer

You should be able to listen for this event, however, the event isn't in your App namespace.

The namespace for the core Auth events is Illuminate\Auth\Events so you would have:

 protected $listen = [
    'Illuminate\Auth\Events\Logout' => [
        'App\Listeners\LogoutEvent'
    ],
];

Hope this helps!