承接 sukohi/back-then 相关项目开发

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

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

sukohi/back-then

Composer 安装命令:

composer require sukohi/back-then

包简介

A Laravel package for managing reivision of database.

README 文档

README

A Laravel package for managing reivision of database. (This package is for Laravel 5+)

Installation

Execute the following composer command.

composer require sukohi/back-then:1.*

then set BackThenServiceProvider in your config/app.php.

Sukohi\BackThen\BackThenServiceProvider::class, 

Preparation

To make a table for this package, execute the following commands.

php artisan vendor:publish --provider="Sukohi\BackThen\BackThenServiceProvider"

and

php artisan migrate

Add BackThenTrait to your model like so.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Sukohi\BackThen\BackThenTrait;

class Product extends Model
{
    use BackThenTrait;

That's all.
Now when you create, update or delete record, this package automatically will save revision record(s).

Usage

You can save and delete record as usual like so.

$product = new \App\Product();
$product->name = 'xxxxxxx';
$product->save();   // Revision record will be saved.

$product = \App\Product::find(1);
$product->name = 'yyyyyyy';
$product->save();   // Revision record will be saved.

$product->delete();   // Revision record will be saved.

Save user ID

You can save ID of user who saved/deleted through revision_user_id.

$product = \App\Product::find(1);
$product->revision_user_id = 1; // User ID you want to save.
$product->save();

Retrieve Current Revision ID and Unique ID

echo $product->revision_id;
echo $product->revision_unique_id;
  • You can change revision you want via revision ID or unique ID.

Change Revision

via changeRevisionById

$revision_id = 1;

if($product->hasRevisionId($revision_id)) {

    $product->changeRevisionById($revision_id); // This has old values.

}

or via changeRevision

$unique_id = '5a906ea1934196bc065f1b22eafd90c9';

if($product->hasRevisionUniqueId($unique_id)) {

    $product->changeRevision($unique_id); // This has old values.

}

Note: Once you call changeRevisionById() or changeRevision(), the model has old values.
This means if you save it, of cause, the latest value will be replaced with the old ones.
So don't forget to call clearRevision() if you need to save at the same time.

Return to the Latest Revision

$product->clearRevision();

Revision Columns

If you'd like this package to save specific revision record.
Set column names in your model like so.

protected $revisions = ['column_name'];

or

protected $ignore_revisions = ['column_name'];

Retrieve Revision data

$histories = $product->revisionHistory; // All revisions

or

$revision = $product->getRevisionById(1);   // A specific revision
$revision = $product->getRevision('5a906ea1934196bc065f1b22eafd90c9');// A specific revision

License

This package is licensed under the MIT License.

Copyright 2017 Sukohi Kuhoh

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固