hanifhefaz/user-model-activity
Composer 安装命令:
composer require hanifhefaz/user-model-activity
包简介
Log activities over models into a log file.
关键字:
README 文档
README
Introduction
Introducing the User Model Activity Package: Effortlessly Track Changes in Your Models
Have you ever found yourself in need of a simple yet effective way to track and log changes made to your Laravel models? Look no further! We are thrilled to present our User Model Activity package, designed to save the logs of model events such as creation, update, and deletion into a convenient log file. With this package, monitoring and auditing changes in your application's models has never been easier.
Installation
You can install the package with Composer.
composer require hanifhefaz/user-model-activity
After installation run the following command to publish the necessary assets and files:
php artisan vendor:publish --provider="Hanifhefaz\UserModelActivity\UserModelActivityServiceProvider"
That's it. You have successfully installed and published the required files and assets of the package.
Usage
Once you have installed and configured the package, you can start using it to track changes in your models. Follow this step-by-step guide to get started:
-
Logging File Configuration
First things is first! Go to your
config/logging.phpand add the following to the channels array:/* * Logging.php */ 'channels' => [ // existing code ... // 'stack' => [ // 'driver' => 'stack', // 'channels' => ['single'], // 'ignore_exceptions' => false, // ], // ... 'user-model-activity' => [ 'driver' => 'single', 'path' => storage_path('logs/user-model-activity.log'), 'level' => 'debug', ], ]
Now, you can use the
UserModelActivityLoggertrait inside the model and all the logs will be tracked.<?php namespace App\Models; use Hanifhefaz\UserModelActivity\Traits\UserModelActivityLogger; use Illuminate\Database\Eloquent\Model; class Post extends Model { use UserModelActivityLogger; protected $fillable = ['title', 'content']; }
That is it. Now just visit
user-model-activityURL and select the file where you saved the logs. You will see all the logs.
Conclusion
The User Model Activity package offers a straightforward and efficient solution for tracking changes made to your Laravel models. It simplifies the process of monitoring, auditing, and debugging model-related changes. Enhance your application's maintainability and gain valuable insights into your data with the User Model Activity package.
Contributions
Contributions are most welcome! Please pick one of the known issues and future plans or implement your own idea to help the package grow.
Current Contributers: Contributors.
Hanif Hefaz |
Known issues and future plans
-
To further enhance the package, we plan to bring some changes in the log views. currently its not optimized.
-
A better approach to integrate user's details as well to the log. currently it will save details of model, and if your model has created_by it will be logged, but we need a better approach for this.
-
Parsing of the logs in a better way.
-
The trait is not working in spatie's Role and Permission models if they are extended from parent model such as below:
<?php namespace App\Models; use Hanifhefaz\UserModelActivity\Traits\UserModelActivityLogger; use Illuminate\Database\Eloquent\Factories\HasFactory; use Spatie\Permission\Models\Permission as ParentPermission; class Permission extends ParentPermission { use HasFactory; use UserModelActivityLogger; protected $fillable = [ 'id','name','created_at','updated_at' ]; }
If you found any issue, please post it to issues section.
hanifhefaz/user-model-activity 适用场景与选型建议
hanifhefaz/user-model-activity 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 4, 最近一次更新时间为 2023 年 10 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logger」 「monitoring」 「laravel」 「logs」 「tracking」 「laravel package」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hanifhefaz/user-model-activity 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hanifhefaz/user-model-activity 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hanifhefaz/user-model-activity 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Symfony bundle for chameleon-system/sanitycheck
SoftWax Health Check Bundle for Symfony framework
1Pilot client for Symfony
Workflow logger
HTTP request logger middleware for Laravel
Statsd (Object Oriented) client library for PHP
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-15
