minex/laravel-change-history 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

minex/laravel-change-history

Composer 安装命令:

composer require minex/laravel-change-history

包简介

Package to record a changes performed on model

README 文档

README

Package to record a changes performed on model.

Installation

composer require minex/laravel-change-history

Package provider is auto discovered.

To publish package migrations use:

php artisan vendor:publish --tag="lch-migrations"

After that run migrations:

php artisan migrate

To change the config, publish it file using the following command:

php artisan vendor:publish --tag="lch-config"

Usage

To record changes for a model add HasChangeHistory trait for it:

use Minex\LaravelChangeHistory\Traits\HasChangeHistory;
use Illuminate\Database\Eloquent\Model;

class SomeModel extends Model {
    use HasChangeHistory;

    /**
     * Attributes in $hidden array will be replaced to **** in history record.
     *
     * @var array
     */
    protected $hidden = ['password', 'other_field'];
}

Note that history based on model events and will not be triggered using query operations

Example:

#This will NOT save a change record
SomeModel::where('is_active', true)->update([
    'is_active' => false,
]);

#This will save a change record
$model = SomeModel::find(1);
$model->is_active = true;
$model->save();

Configuration

If you want to ignore some attributes in history use:

use Minex\LaravelChangeHistory\Traits\HasChangeHistory;
use Illuminate\Database\Eloquent\Model;

class SomeModel extends Model {
    use HasChangeHistory;

    public array $lch_ignore_attrs = ['updated_at', 'deleted_at'];
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-18