voerro / laravel-visitor-tracker

Visitor tracker and statistics for Laravel 5.5+ (abandoned for the time being, feel free to take over)
66 stars 40 forks source link

How can I see online users? #18

Closed lipasite closed 5 years ago

lipasite commented 5 years ago

Is it possible to get stats by current online users?

hamza-attiq commented 5 years ago

Any Luck ?

ashniazi commented 5 years ago

Didn't use this package, but if there is a field in the database that showcases the last date a user has signed in you can create a calculation based on 'an active user is considered to have a date that's within 3 minutes of the update_at field' or something.

Like logic wise - perhaps similar to this:

    public function getOnlineStatusAttribute(){
        $timeout = 3; //3 minutes
        if($this->session != null){
            $now = Carbon::now();
            $diff = $this->session->updated_at->diffInMinutes($now);
            return ($diff <= $timeout) ? true : false;
        }
    }