good-system/laravel-model-history
Composer 安装命令:
composer require good-system/laravel-model-history
包简介
README 文档
README
Installation
composer require good-system/laravel-model-history
composer migrate
Usage
Use Generic ModelObserver
If model history logging/recording for "created" and "updated" are the only things you need to do in a model observer, simply add something like the following to your service provider class:
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
Donation::observe(\GoodSystem\ModelHistory\ModelObserver::class);
}
}
And two model actions will be logged in database table model_history
- new donation created
- donation updated
Use Trait ModelChangeEventTraits
If your model observer needs to observe additional model events, but for "created" and "updated" events, model history logging/recording is the only thing needed, trait ModelChangeEventTraits could be added to observer class, like this
class YOUR_MODEL_Observer
{
use \GoodSystem\ModelHistory\ModelChangeEventTraits;
// other model events such as deleted, saved, etc.
}
Use ModelFieldHistory model static methods directly
Model class ModelFieldHistory provides two additional methods
forModelCreated()- record newly created modelforFieldChanges()- record changes made to the model
If your model observer's "created" or "updated" event needs to do history logging/recording, plus other things, these two methods can be called from the observer directly, like this:
class YOUR_MODEL_Observer
{
public function updated(YOUR_MODEL $modelObject)
{
ModelHistory::forFieldChanges(auth()->user(), $modelObject)->save();
// Other things that need to be done upon model record update
}
public function created(YOUR_MODEL $modelObject)
{
ModelHistory::forModelCreated(auth()->user(), $modelObject)->save();
// Other things that need to be done upon model record creation
}
}
Other Usage
No other usage at this point. Note that the database table is not limited to accommodate these two changes.
good-system/laravel-model-history 适用场景与选型建议
good-system/laravel-model-history 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 55 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 11 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 good-system/laravel-model-history 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 good-system/laravel-model-history 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 55
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2018-11-20