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
You can also set these variables in your .env file (example below).
Note: This repository currently runs CI only for Laravel 12. The older per-version workflow files for Laravel 10 and 11 were removed to simplify the workflow matrix and remove duplicate CI runs. If you need per-Laravel-version badges again, recreate the per-version workflows or restore
run-tests-laravel-10.ymlandrun-tests-laravel-11.yml.
"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 and configuration 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.phpfile in your Laravel project. -
Locate the
$middlewareGroupsproperty, specifically within thewebmiddleware group. - Add the following line to the
webmiddleware group:
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.phpfile in your Laravel project. -
Locate the
schedulemethod and add the following entry to schedule thecleanup:inactive-userscommand every five minutes: - Save the changes to the
Kernel.phpfile.
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:
env ONLINE_USERS_ANONYMIZE_IP=true ONLINE_USERS_IP_SALT=your-long-random-salt bash php artisan vendor:publish --tag="online-users-migrations" php artisan migrate bash php artisan online-users:populate-ip-hash bash php artisan vendor:publish --tag="online-users-migrations" php artisan migrate
Before dropping raw IPs, please ensure you have a backup of your database. Recommended workflow:
1. Make a backup of your database.
2. Run `php artisan migrate` to add `user_ip_hash` (if not already present).
3. Run `php artisan online-users:populate-ip-hash` to fill the `user_ip_hash` column.
4. Verify data and application functionality.
5. If all good, run `php artisan migrate` which will pick up the `drop` migration to remove the `user_ip` column.
**Note:** hashing is irreversible; if you need the raw IP for logging, do not enable this option.
## 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](LICENSE.md) for more information.
## Automated Code Style Fixes
This project runs `php-cs-fixer` in CI. To allow the code-style workflow to auto-commit fixes back to pull requests, add a repository secret named `STYLE_BOT_TOKEN` with a personal access token (PAT) that has `repo` permissions. When set, the workflow will commit fixes directly to the PR branch.
If you do not set `STYLE_BOT_TOKEN`, the workflow will attempt to use the default `GITHUB_TOKEN` where permitted (works for branches in the same repository but not for PRs from forks).
When the workflow runs on a PR it will now create a new pull request with automatic style fixes (rather than pushing changes directly to the originating branch). The original PR will receive a comment linking to the fixes PR.