how check the online user in laravel

Solutions on MaxInterview for how check the online user in laravel by the best coders in the world

showing results for - "how check the online user in laravel"
Iker
20 Jan 2020
1//1 - the first step make middleware
2
3public function handle($request, Closure $next)
4    {
5        if(Auth::check()) {
6            $expiresAt = Carbon::now()->addMinutes(1);
7            Cache::put('user-is-online-' . Auth::user()->id, true, $expiresAt);
8        }
9        return $next($request);
10    }
11
12// the second step is add a class into Kernel
13
14//the third step is add a function into the User Model
15public function isOnline()
16{
17    return Cache::has('user-is-online-' . $this->id);
18}
19
20//the last step is check user Online or offline in Laravel application
21@if($user->isOnline())
22    user is online!!
23@endif