brianclogan/laravel-user-status
Composer 安装命令:
composer require brianclogan/laravel-user-status
包简介
Track user status automatically, or have custom statuses set.
README 文档
README
Track user status automatically, or have custom statuses set by the user.
Originally, this package was going to be for users, but I realized that it could be used for any model that you want to track the status of (ie: Teams).
So, while it's called Laravel User Status, it can be used for any model that you want to track the status of.
Features
- Automatically track user status
- Custom statuses
- Real-time status updates
- Keep history of statuses
- Customizable
- Laravel Echo support
Installation
You can install the package via composer:
composer require brianclogan/laravel-user-status
You can publish and run the migrations with:
php artisan vendor:publish --tag="laravel-user-status-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="laravel-user-status-config"
This is the contents of the published config file:
return [ /** * Tables * * The table names used by the package. */ 'tables' => [ 'status_table' => env('USER_STATUS_TABLE', 'user_statuses'), ], /** * Laravel Echo Configuration * * This is used to broadcast the status changes to the frontend * and update the status in real-time. (if enabled) */ 'echo' => [ /** * Enable or disable the broadcasting of the status changes */ 'enabled' => env('USER_STATUS_ECHO_ENABLED', false), 'channel' => 'statusable.{type}.{id}', /** * Enable or disable the broadcasting of the presence changes */ 'presences_enabled' => env('USER_STATUS_PRESENCES_ENABLED', false), 'presences' => 'statusable.{type}.{id}.presences', ], /** * Middleware * * This is applied when a user makes a request. It will update the user's status * based on the configuration below. * * If you want to disable this, set `enabled` to false. * * If you want to apply this to a different group, you can add more groups to the `groups` array. * If you apply `api`, it will set the user status online for any API request which is not recommended. * * Feel free to disable this, and make your own middleware if you want. */ 'middleware' => [ 'enabled' => env('USER_STATUS_MIDDLEWARE_ENABLED', true), 'groups' => [ 'web', ], 'status' => 'online', 'reason' => 'active', 'meta' => null, ], /** * Status Model * * The model used to store the statuses, you can extend the model * and change the class here. NOT RECOMMENDED, but possible. */ 'status_model' => \BrianLogan\LaravelUserStatus\Models\Status::class, /** * Keep History * * If enabled, the package will keep past statuses in the database. * * This is useful for analytics and other purposes, but is disabled * by default to reduce the size of the database. * * If you enable this, you should also enable the `echo.enabled` option * to keep the frontend in sync with the backend. * * This will update the status model to use a morphMany relationship * instead of a morphOne relationship. */ 'keep_history' => env('USER_STATUS_KEEP_HISTORY', false), ];
Usage
Add the HasStatus trait to the model you want to track the status of.
use BrianLogan\LaravelUserStatus\Traits\HasStatus; class User extends Model { use HasStatus; }
Get the latest status
$user = User::find(1); $user->getLatestStatus();
Set a status
When calling setStatus, only the status is required. The reason and meta are optional.
meta can be used to store additional information about the status, such as colors, icons, custom messages, etc.
$user = User::find(1); $user->setStatus(status: 'active', reason: 'User is active', meta: ['foo' => 'bar']);
NOTE: If you have
keep_historyenabled, rather than updating the status, it will create a new record.
Scopes
Get all with a specific status
User::whereStatus('active')->get();
NOTE: If you have
keep_historyenabled, it will return all records with the status, not just the latest.
Get all with a specific status reason
User::whereStatusReason('User is active')->get();
NOTE: If you have
keep_historyenabled, it will return all records with the status, not just the latest.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
brianclogan/laravel-user-status 适用场景与选型建议
brianclogan/laravel-user-status 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 05 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「laravel-user-status」 「Brian Logan」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 brianclogan/laravel-user-status 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 brianclogan/laravel-user-status 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 brianclogan/laravel-user-status 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Addressable Polymorphic Eloquent Models for Laravel 5
Alfabank REST API integration
Addressable Polymorphic Eloquent Models for Laravel
This is my package laravel-user-status
reportable Polymorphic Eloquent Models for Laravel 5
Laravel package for Accurate Online API integration.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-05