承接 devitek/eloquent-loggable 相关项目开发

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

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

devitek/eloquent-loggable

Composer 安装命令:

composer require devitek/eloquent-loggable

包简介

Make your eloquent Model loggable

README 文档

README

SensioLabsInsight Latest Stable Version Total Downloads Latest Unstable Version License

This package provide a simple way to make your Eloquent's model loggable. It works like the Gedmo/Loggable extension for doctrine.

Installation

Run :

composer require devitek/eloquent-loggable

Into your config/app.php add the service provider :

'providers' => [
    // Other Service Providers

    Devitek\Laravel\Eloquent\Loggable\EloquentLoggableServiceProvider::class,
],

Get the migration :

php artisan vendor:publish --provider="Devitek\Laravel\Eloquent\Loggable\EloquentLoggableServiceProvider" --tag="migrations"

and then run :

php artisan migrate

How to use it

In your Eloquent model add :

<?php

use \Devitek\Laravel\Eloquent\Loggable;

class MyModel extends Model
{
    use Loggable;

    protected $versioned = [
        'name',
        'other_field',
        'another_field',
        'again_another_field',
    ];
    
    protected $reason = 'my_reason_field';
}

Now, each time you'll persist your model, all fields that are declared in the versioned property will be checked (if dirty) and then logged.

The reason property indicates which field will be used to have a log message. It's not required, by default the log message will be empty. This field will be unset before persist so you can use a dynamic field.

Get log entries

You now have a method on your model : logEntries which is a morphTo relationship.

$logEntries = $model->logEntries();

foreach ($logEntries as $logEntry) {
    /**
     * LogEntry object :
     * action, logged_at, object_id, version, reason, data (as json), user_id
     */
}

Revert

You can revert your model to a previous state using the revert method like so :

$model = MyModel::find($id);

$model->revert(); // Revert to the first revision
$model->revert(5); // Revert to the 5th revision

Enjoy it ! Feel free to fork :) !

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固