定制 fico7489/laravel-revisionable-upgrade 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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;

See more

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 fico7489/laravel-revisionable-upgrade 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 39.84k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 53
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 53
  • Watchers: 4
  • Forks: 11
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-11-23