fico7489/laravel-revisionable-upgrade
Composer 安装命令:
composer require fico7489/laravel-revisionable-upgrade
包简介
Upgrade for the venturecraft revisionable package, add many useful methods.
关键字:
README 文档
README
Upgrade for the Venturecraft Revisionable package, many useful methods are added.
Why to use
Yeah, revisionable package has userResponsible () method, but that is not enough and we can use saved revisions for much more useful stuff. We can find out who created, deleted and edited model, when the model was edited, when exact attribute from the model was edited and much more.
- You don't need to add updated_by, deleted_by, created_by to your tables.
- You don't need to add updated_attribute_by to your tables.
- You don't need to add updated_attribute_to_value_by to your tables.
- You don't need to add updated_attribute_from_value_to_value_by to your tables.
- You don't need to add updated_attribute_at to your tables.
- You don't need to add updated_attribute_to_value_at to your tables.
- You don't need to add updated_attribute_from_value_to_value_at to your tables.
- You don't need author_id, created_user_id, deleted_user_id etc. or anything like that
Don't pollute your tables with above table columns in the database, all above information is already stored in revisions table we just need the ability to get them, and this package will help you with that.
Version Compatibility
The package is available for larvel 5.* versions
Install
1.Install package with composer
composer require fico7489/laravel-revisionable-upgrade:"*"
2.Use Fico7489\Laravel\RevisionableUpgrade\Traits\RevisionableUpgradeTrait trait in your base model or only in particular models. Model which use RevisionableUpgradeTrait must also use RevisionableTrait;
...
use Venturecraft\Revisionable\RevisionableTrait;
use Fico7489\Laravel\RevisionableUpgrade\Traits\RevisionableUpgradeTrait;
abstract class BaseModel extends Model
{
use RevisionableTrait;
use RevisionableUpgradeTrait;
//enable this if you want use methods that gets information about creating
protected $revisionCreationsEnabled = true;
...
and that's it, you are ready to go.
New methods
-
userCreated() Returns user which created this model
-
userDeleted() Returns user which deleted this model
-
userUpdated($key = null, $newValue = null, $oldValue = null) Returns user which updated this model (last user if there are more)
-
revisionCreated() Returns revision for model created
-
revisionDeleted() Returns revision for model deleted
-
revisionUpdated($key = null, $newValue = null, $oldValue = null) Returns revision for model updated (last revision if there are more)
-
dateUpdated($key = null, $newValue = null, $oldValue = null) Returns date(Carbon\Carbon) for model updated (last revision if there are more)
-
revisionsUpdated($key = null, $newValue = null, $oldValue = null) Returns revisions for model updated
-
usersUpdated($key = null, $newValue = null, $oldValue = null) Returns users for model updated
Clarification for methods with ($key = null, $newValue = null, $oldValue = null)
- All parameters are optional
- If you provide $key method will look for changes on that key/field
- If you provide $newValue method will look for changes where key/field is changed to this value
- If you provide $oldValue method will look for changes where key/field is changed from this value
We don't need dateCreated and dateDeleted because information about this is stored in created_at and deleted_at. We don't need revisionsCreated, revisionsDeleted, usersCreated, usersDeleted because model can be created or deleted only once. Methods which returns user and users are using model from auth.model configuration.
See some action
$seller = Seller::create(['email' => 'test@test.com']);
//get user who edited model
$seller->userCreated();
//get user who deleted model
$seller->userDeleted();
//get user who updated model
$seller->userUpdated();
//get user who updated attribute name in model
$seller->userUpdated('name');
//get user who updated attribute name value to 'new_name'
$seller->userUpdated('name', 'new_name');
//get user who updated attribute name value to 'new_name' value from 'old_name' value
$seller->userUpdated('name', 'new_name', 'old_name');
//get revision model for create
$seller->revisionCreated();
//get revision model for delete
$seller->revisionDeleted();
//get revision model for update
$seller->revisionUpdated();
//get date for update
$seller->dateUpdated();
//get revisions for update
$seller->revisionsUpdated();
//get users for update
$seller->usersUpdated();
Improtant notes
Models where you want use this package must use created_at timestamp
If you want fetch users that have deleted models you must enable $revisionCreationsEnabled
protected $revisionCreationsEnabled = true;
License
MIT
Free Software, Hell Yeah!
fico7489/laravel-revisionable-upgrade 适用场景与选型建议
fico7489/laravel-revisionable-upgrade 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 39.84k 次下载、GitHub Stars 达 53, 最近一次更新时间为 2017 年 11 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel revisionable upgrade」 「laravel updated_by」 「laravel deleted_by」 「laravel created_by」 「laravel updated_at by key」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fico7489/laravel-revisionable-upgrade 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fico7489/laravel-revisionable-upgrade 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fico7489/laravel-revisionable-upgrade 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Nice and easy way to handle revisions of your db.
Helper classes dependency for Laravel Enso
Run upgrade wizards for multiple TYPO3 versions at once
Fork of VentureCraft/revisionable
A package for keeping a history of your models' revisions and accessing your data as it was at an older date.
Makes Laravel Models revisionable
统计信息
- 总下载量: 39.84k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 53
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-11-23