Search code examples
laraveleventsoverriding

How can I override laravel logout core event?


I'm trying to broadcast Illuminate\Auth\Events\Logout. Is it possible to override or extend this core event so as to include BroadcastOn method?


Solution

  • You cannot override the core logout event. There are two ways about this problem. Either way, you will have to fire your custom event.

    1. Override loggedOut() method in AuthenticatesUsers:

    You will have to create your custom event and override loggedOut() method in AuthenticatesUsers to fire it manually like so:

    protected function loggedOut(Request $request)
    {
        event(new CustomLogoutEvent());
    }
    

    This will fire the core event and your custom one.

    1. Override SessionGuard to override logout() (lengthy and not suggested):

    logout() in SessionGuard is where the core logout event is triggered. Override it to only fire your custom event. This way only one logout event is fired.

    Here is how to override guards: https://laravel.com/docs/7.x/authentication#adding-custom-guards