quarks/laravel-auditors

在Eloquent模型上自动记录创建者、更新者和删除者。

1.2.1 2022-01-08 18:50 UTC

This package is auto-updated.

Last update: 2024-09-09 01:11:35 UTC


README

在Eloquent模型上自动记录创建者、更新者和删除者(如果添加了软删除)。

Latest Version Downloads PHP Version License

安装

composer require quarks/laravel-auditors

使用方法

在你的迁移类中,将审计者列添加到你的表中,如下所示

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::table('users', function (Blueprint $table) {
        $table->auditors();
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::table('users', function (Blueprint $table) {
        $table->dropAuditors();
    });
}

然后按照以下方式在你的模型类中添加 HasAuditors 特性

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Quarks\Laravel\Auditors\HasAuditors;

class User extends Authenticatable
{
    use HasAuditors;
}

从现在起,此模型上的 createdByupdatedBydeletedBy 关系将分别自动保存到 createdupdateddeleted 模型事件。

许可

查看LICENSE文件。