Can you obtain the user id from the Auth Logout event?

Top of the world | Soft Technoes
I am using Listeners in a Laravel 5.8 application to log User actions.
I would like to create a log record for when the User Logs in and Out.
My Login functionality is working fine: i can retrieve the user id via auth()->id().
I am having problems identifying the logged out user id in the Logout functionality.
I have my subscriber:

        $events->listen(
            'Illuminate\Auth\Events\Logout',
            'App\Listeners\UserEventSubscriber@handleUserLogout'
        );
and i am trying to find the user id of the logged out user...
<?php

namespace App\Listeners;

use Log;
use Auth;
use Illuminate\Auth\Events\Logout;
use Illuminate\Auth\Events\Login;
use App\User;

class UserEventSubscriber
{    
public function handleUserLogout($event) {
        return $this->recordCandActivity(array(auth()->id(), 'logged out', 'User logged Out', 'Logout', 'No link'));
    }
but auth()->id() is (of course) rendered empty post logout.
Does anyone know a way of retrieving the just logged out user id from the Auth Logout event?
Thanks in advance.

Your Answer


Post a Comment

0 Comments