{"id":33993985,"url":"https://github.com/klevze/online-users","last_synced_at":"2025-12-13T07:38:32.690Z","repository":{"id":216609130,"uuid":"741794642","full_name":"klevze/online-users","owner":"klevze","description":"Laravel plugin for displaying online users on a webpage","archived":false,"fork":false,"pushed_at":"2025-11-15T15:55:51.000Z","size":925,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-15T16:23:26.625Z","etag":null,"topics":["count","laravel","laravel-package","online","php","users"],"latest_commit_sha":null,"homepage":"https://thewallpapers.net","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/klevze.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-01-11T05:57:34.000Z","updated_at":"2025-11-15T15:55:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"426eff2e-1e4f-4e7a-8509-084788481e67","html_url":"https://github.com/klevze/online-users","commit_stats":null,"previous_names":["klevze/online-users"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/klevze/online-users","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klevze%2Fonline-users","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klevze%2Fonline-users/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klevze%2Fonline-users/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klevze%2Fonline-users/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/klevze","download_url":"https://codeload.github.com/klevze/online-users/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klevze%2Fonline-users/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27702077,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-13T02:00:09.769Z","response_time":147,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["count","laravel","laravel-package","online","php","users"],"created_at":"2025-12-13T07:38:28.481Z","updated_at":"2025-12-13T07:38:32.682Z","avatar_url":"https://github.com/klevze.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel plugin for displaying online users on a webpage\n\n\u003c!-- Project cover image --\u003e\n![Online Users](assets/card.png)\n\nYou can also set these variables in your `.env` file (example below).\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/klevze/online-users.svg?style=flat-square)](https://packagist.org/packages/klevze/online-users)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/klevze/online-users/run-tests-laravel-12.yml?branch=main\u0026label=tests\u0026style=flat-square)](https://github.com/klevze/online-users/actions?query=workflow%3Arun-tests-laravel-12+branch%3Amain)\n\n\u003c!-- Per-Laravel-version badges (each runs a workflow file) --\u003e\n[![Laravel 12](https://img.shields.io/github/actions/workflow/status/klevze/online-users/run-tests-laravel-12.yml?branch=main\u0026label=Laravel%2012\u0026style=flat-square)](https://github.com/klevze/online-users/actions?query=workflow%3Arun-tests-laravel-12+branch%3Amain)\n[![Laravel 12](https://img.shields.io/github/actions/workflow/status/klevze/online-users/run-tests-laravel-12.yml?branch=main\u0026label=Laravel%2012\u0026style=flat-square)](https://github.com/klevze/online-users/actions?query=workflow%3Arun-tests-laravel-12+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/klevze/online-users/fix-php-code-style-issues.yml?branch=main\u0026label=code%20style\u0026style=flat-square)](https://github.com/klevze/online-users/actions?query=workflow%3A\"Fix+PHP+code+style+issues\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/klevze/online-users.svg?style=flat-square)](https://packagist.org/packages/klevze/online-users)\n\n\u003e 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.yml` and `run-tests-laravel-11.yml`.\n\n\"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.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require klevze/online-users\n```\n\nYou can publish and run the migrations and configuration with:\n\n```bash\nphp artisan vendor:publish --tag=\"online-users-migrations\"\nphp artisan vendor:publish --tag=\"online-users-config\"\nphp artisan migrate\n```\n\n## Integration with Laravel's Kernel Middleware\n\nTo enable the \"Online Users\" middleware in your Laravel application, follow these steps:\n\n1. Open the `app/Http/Kernel.php` file in your Laravel project.\n\n2. Locate the `$middlewareGroups` property, specifically within the `web` middleware group.\n\n3. Add the following line to the `web` middleware group:\n\n   ```php\n   protected $middlewareGroups = [\n       'web' =\u003e [\n           // ... other middleware entries\n           \\Klevze\\OnlineUsers\\Middleware\\TrackUserActivity::class,\n           // ... other middleware entries\n       ];\n\n   ```\n\n\u003c!-- Demo moved to the bottom of README --\u003e\nThe \"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.\n\n1. Open the `app/Console/Kernel.php` file in your Laravel project.\n\n2. Locate the `schedule` method and add the following entry to schedule the `cleanup:inactive-users` command every five minutes:\n\n    ```php\n    protected function schedule(Schedule $schedule)\n    {\n        // ... other scheduled tasks\n\n        $schedule-\u003ecommand('cleanup:inactive-users')-\u003eeveryFiveMinutes();\n\n        // ... other scheduled tasks\n    }\n    ```\n\n3. Save the changes to the `Kernel.php` file.\n\nNow, the \"CleanupInactiveUsers\" console command will run every five minutes, cleaning up inactive users from the `user_activities` table.\n\n## Usage\n\nOnce 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:\n\n```php\n$activeUsers = OnlineUsers::getActiveUsers();\n```\n\nOr you can use it directly in blade view:\n\n```html\n\u003cp\u003eCurrently browsing: {{ OnlineUsers::getActiveUsers() ?? 0 }}\u003c/p\u003e\n\nYou can customize the activity threshold and tracking strategy by publishing and editing the `config/online-users.php` file.\n\nCompatibility: This package supports Laravel 10, 11 and 12 and requires PHP 8.1 or newer. If you are using Laravel 12, ensure your application meets Laravel 12's PHP requirements.\n\n### IP anonymization (privacy)\n\nFor privacy-conscious deployments you can anonymize user IP addresses before saving them to the database. To enable anonymization:\n\n1. Publish the config: `php artisan vendor:publish --tag=\"online-users-config\"`.\n2. Set `anonymize_ip` to `true` and set `ip_salt` to a large secret string in `config/online-users.php` or via environment variables.\n\nOr set in your `.env`:\n\n```env\nONLINE_USERS_ANONYMIZE_IP=true\nONLINE_USERS_IP_SALT=your-long-random-salt\n```\n\nWhen enabled, the package will store a sha256 hash of the IP address concatenated with the salt to help protect user privacy while still allowing approximate uniqueness checks.\n\n### Upgrading and migrating existing installs\n\nTo add the `user_ip_hash` column (if you installed the package before hashed IP support was added) you should publish and run the new migration:\n\n```bash\nphp artisan vendor:publish --tag=\"online-users-migrations\"\nphp artisan migrate\n```\n\n\nAfter running the migration you can populate the newly created hash column using this command (requires a valid `ONLINE_USERS_IP_SALT`):\n\n```bash\nphp artisan online-users:populate-ip-hash\n```\n\nThe `online-users:populate-ip-hash` command will compute the hash for rows that don't yet have one. It uses your configured `ONLINE_USERS_IP_SALT` and `ONLINE_USERS_HASH_ALGORITHM`.\n\nIf you want to keep raw IPs along with hashed IPs for additional analysis, set `ONLINE_USERS_STORE_RAW_IP=true`.\n\n### Dropping raw IPs (optional)\n\nIf you decide to stop storing raw IPs after you are certain `user_ip_hash` has been populated, run the migration that removes the raw column:\n\n```bash\nphp artisan vendor:publish --tag=\"online-users-migrations\"\nphp artisan migrate\n```\n\nBefore dropping raw IPs, please ensure you have a backup of your database. Recommended workflow:\n\n1. Make a backup of your database.\n2. Run `php artisan migrate` to add `user_ip_hash` (if not already present).\n3. Run `php artisan online-users:populate-ip-hash` to fill the `user_ip_hash` column.\n4. Verify data and application functionality.\n5. If all good, run `php artisan migrate` which will pick up the `drop` migration to remove the `user_ip` column.\n\n\n**Note:** hashing is irreversible; if you need the raw IP for logging, do not enable this option.\n\n## Demo\n\nYou can see a working demo at these sites:\n\n- [The Wallpapers](https://thewallpapers.net)\n- [Joke Station](https://jokestation.org)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n## Automated Code Style Fixes\n\nThis 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.\n\nIf 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).\n\nWhen 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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklevze%2Fonline-users","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fklevze%2Fonline-users","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklevze%2Fonline-users/lists"}