jeudi 18 avril 2019

How to get Last seen online time in Laravel

In User profile view i need to show user's online status. If he/she is online will show online if not then need to show Last seen at 4:30 PM . I am using Laravel's Cache for this. I have created a middleware called LastUserActivity it looks like this.

public function handle($request, Closure $next) {
    if (Auth::check()):
        $expiresAt = Carbon::now()->addMinutes(1);
        Cache::put('user-is-online-' . Auth::id(), true, $expiresAt);
    endif;
    return $next($request);
}

then on user model i have a method

public function isOnline() {
    return Cache::has('user-is-online-' . $this->id);
}

By doing this i am getting status online or not but how will i get Last seen -----.

Thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire