nhayder
2 months ago

Count logged in Users

Posted 2 months ago by nhayder

I have a middleware that will add user to array every time a user login to his account

    public function handle($request, Closure $next)
    {
        if(Auth::check()) {
            
            $lastSeen = Carbon::now()->format('y-m-d H:i:s');

            $onlineUsers = json_decode(Cache::get('isOnline', '{}'), true);

            $onlineUsers[ Auth::id() ] = $lastSeen;

            Cache::put('isOnline', json_encode($onlineUsers), 60); // store for 2 minutes

        }

        return $next($request);
    }

Now i need to check how many users are in that array from blade template file ????

Any ideas on how to do this ????

Please sign in or create an account to participate in this conversation.