承接 johannesschobel/laravel-revisionable 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

johannesschobel/laravel-revisionable

Composer 安装命令:

composer require johannesschobel/laravel-revisionable

包简介

Makes Laravel Models revisionable

README 文档

README

Easy and conventient way to handle revisions of your models within the database.

  • Handles the revisions in bulk - one entry covers all the created/updated fields, what makes it really easy to e.g., compare 2 given versions or get all the data changed during one single transaction.

Requirements

  • This package requires PHP 5.4+
  • Currently it works out of the box with Laravel5.4 + generic Illuminate Guard, tymon/jwt-auth OR cartalyst/sentry 2/sentinel 2

Usage (Laravel 5 basic example - see Customization below as well)

1. Download the package or require in your composer.json:

composer require johannesschobel/laravel-revisionable

2. Add the service provider to your app/config/app.php:

    'providers' => array(
        ...
        'JohannesSchobel\Revisionable\RevisionableServiceProvider',
    ),

3. Publish the package config file:

~$ php artisan vendor:publish [--provider="JohannesSchobel\Revisionable\RevisionableServiceProvider"]

this will create config/revisionable.php file, where you can adjust a few settings.

4. Run the migration in order to create the revisions table:

~$ php artisan migrate

5. Add revisionable trait to the models you wish to keep track of:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use JohannesSchobel\Revisionable\Traits\Revisionable;

class User extends Model
{
    use Revisionable;
}    

And that's all to get you started!

Customization

The package offers a set of configuration options.

White-Listing Fields

If you would like to revision only specific fields of the model, you can define them like so:

    /*
     * Set revisionable whitelist - only changes to any
     * of these fields will be tracked during updates.
     */
    protected $revisionable = [
        'email',
        'name'
    ];

This way, only the fields email and name are tracked and store as revision in the database. The default behaviour is to revision all fields.

Disable Revisions

If you want to disable revisions for a specific model just add the following variables to your model

    protected $revisionEnabled = false;

Revision Cleanup

You can further specify that you only want to clean up old revisions of a model. By doing so, you can further define, how many revisions of one model you would like to keep in your database (default is set to 20). Say, if you add the 21st revision, the first one is deleted.

You may customize this behaviour for each model by changing the variables

    protected $revisionLimitCleanup = true; // only works with revisionLimit
    protected $revisionLimit = 50;  // keep 50 instead of 20 revisions of this model

Rollback (aka load old revisions)

Of course, you can rollback to an old revision of your model. The Trait added earlier (e.g., the Revisionable trait) already provides handy methods for you - so you don't need to worry about this.

You can either use the $model->rollbackToTimestamp($timestamp) or $model->rollbackSteps($steps) functions for this purpose. Note that there is a configuration flag revisionable.rollback.cleanup (default false) that indicates, whether the revisions rolled back should be deleted (true) or not (false).

Both functions return the rolled back model, which is already persisted in the database.

Demonstration

$ php artisan tinker

>>> $ticket = App\Models\Ticket::first();
=> <App\Models\Ticket>

>>> $revision->getDiff();
=> [
       "customer_id"    => [
           "old" => "1",
           "new" => "101"
       ],
       "item_id"        => [
           "old" => "2",
           "new" => "1"
       ],
       "responsible_id" => [
           "old" => "8",
           "new" => "2"
       ]
   ]

>>> $revision->old('item_id');
=> "2"

>>> $revision->new('item_id');
=> "1"

>>> $revision->isUpdated('item_id');
=> true

>>> $revision->isUpdated('note');
=> false

>>> $revision->label('item_id');
=> "item_id"

>>> $revision->old;
=> [
       "defect"         => "foo",
       "note"           => "bar",
       "customer_id"    => "1",
       "item_id"        => "2",
       "responsible_id" => "8",
       "status_id"      => "6"
   ]

>>> $revision->action;
=> "updated"

johannesschobel/laravel-revisionable 适用场景与选型建议

johannesschobel/laravel-revisionable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.26k 次下载、GitHub Stars 达 17, 最近一次更新时间为 2017 年 05 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「eloquent」 「revision」 「history」 「revisionable」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 johannesschobel/laravel-revisionable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 johannesschobel/laravel-revisionable 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 17
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-05-29