Download the PHP package klevze/online-users without Composer
On this page you can find all versions of the php package klevze/online-users. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package online-users
Laravel plugin for displaying online users on a webpage
"Online Users" is a Laravel package designed to effortlessly track and display the real-time count of users currently active on your web application. With seamless integration, this package provides a quick and reliable solution for monitoring and presenting the dynamic online user presence, enhancing the overall user experience on your Laravel-powered website.
Installation
You can install the package via composer:
You can publish and run the migrations with:
Integration with Laravel's Kernel Middleware
To enable the "Online Users" middleware in your Laravel application, follow these steps:
-
Open the
app/Http/Kernel.php
file in your Laravel project. -
Locate the
$middlewareGroups
property, specifically within theweb
middleware group. - Add the following line to the
web
middleware group:
Cleanup Inactive Users Console Command
The "CleanupInactiveUsers" console command provided by the "Online Users" package allows you to remove inactive users from the user_activities
table. Follow the steps below to integrate and schedule the cleanup task.
-
Open the
app/Console/Kernel.php
file in your Laravel project. -
Locate the
schedule
method and add the following entry to schedule thecleanup:inactive-users
command every five minutes: - Save the changes to the
Kernel.php
file.
Now, the "CleanupInactiveUsers" console command will run every five minutes, cleaning up inactive users from the user_activities
table.
Usage
Once package is installed, you can use the OnlineUsers
class to get the number of active users. For example, the following code will get the number of active users:
Or you can use it directly in blade view:
Demo
You can see a working demo at these sites:
- The Wallpapers: https://thewallpapers.net
- Joke Station: https://jokestation.org
License
The MIT License (MIT). Please see License File for more information.