Laravel check User online offline

Today, We want to share with you Laravel check User online offline.In this post we will show you Laravel CHECK IF USER ONLINE OR AWAY SCRIPT, hear for Who is online Laravel script to display active Users at any moment we will give you demo and example for implement.In this post, we will learn about Laravel Check Member’s/ User’s Online or Offline Status with an example.

Laravel check User online offline

There are the Following The simple About Laravel check User online offline Full Information With Example and source code.

READ :  How to Find The Total Number of Products in WP REST API v3?

As I will cover this Post with live Working example to develop how to show live online user using Laravel with ajax jquery, so the how to check how many user online in Laravel for this example is following below.

Step:1 Create a fresh Laravel project
[php]
laravel new fbchat
[/php]

Step:2 Setup MySQL database and migrate table
[php]
php artisan migrate
[/php]

Step: 3 make a Laravel middleware
[php]
php artisan make:middleware CheckUserOnlineOffline
[/php]

App\Http\Middleware\CheckUserOnlineOffline .php
[php]
addMinutes(1);
Cache::put(‘user-is-online-‘ . Auth::user()->id, true, $useroffAt);
}
return $next($request);
}
}
[/php]

Step: 4 Add a class into Kernel
[php]
\App\Http\Middleware\CheckUserOnlineOffline::class,
[/php]

Add $middlewareGroups
[php]
protected $middlewareGroups = [
‘web’ => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,

READ :  vue js serialize form submit in Laravel

\App\Http\Middleware\CheckUserOnlineOffline::class,
],

‘api’ => [
‘throttle:60,1’,
‘bindings’,
],
];
[/php]

Step: 5 Include a simple function into the User http Model
[php]
public function isCheckOnlineOrNot()
{
return Cache::has(‘user-is-online-‘ . $this->id);
}
[/php]

Step: 6 Check current user Online or offline in Laravel Web application
[php]
@if($user->isCheckOnlineOrNot())
user is online!!
@endif
[/php]
how to check online users on website

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel check User online offline.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

READ :  Laravel INSERT UPDATE DELETE Example Step By Step

Leave a Comment