ianbarnes/model-log

Voyager 模型日志

v1.0.3 2020-08-02 09:49 UTC

This package is auto-updated.

Last update: 2024-09-29 05:55:48 UTC


README

安装钩子

php artisan hook:install model-log

启用钩子

php artisan hook:enable model-log

发布配置

php artisan vendor:publish --provider="Jahondust\ModelLog\ModelLogServiceProvider"

如何使用模型日志

Voyager 模型日志用于通过在数据库的 "model-log" 表中写入来观察模型中的任何变化。您只需在模型中添加 "use ModelLogging;" 即可使用它。

示例

<?php
namespace App;

use Illuminate\Database\Eloquent\Model;
use Jahondust\ModelLog\Traits\ModelLogging;

class Post extends Model
{
	use ModelLogging;
}

如果您想排除或包含模型字段的更改,只需从模型的 "$logFields" 属性中删除或添加字段即可。

示例

$logFields = ['title'];

如果您想在 "model-log" 表中不同地显示 "user" 字段,请向您的 User 模型添加 "getLogNameAttribute" 属性。

示例

public function getLogNameAttribute()
{
   return $this->firstname . " " . $this->lastname;
}

Voyager model log