frengky / laravel-auditable
Laravel Eloquent 模型审计
dev-main
2021-03-31 08:08 UTC
Requires
- php: ^7.2.5|^8.0
Requires (Dev)
- illuminate/database: ^7|^8
- illuminate/support: ^7|^8
This package is auto-updated.
Last update: 2024-09-29 05:49:52 UTC
README
简介
此包帮助审计模型数据变更,包括创建、更新和删除(审计跟踪)
安装
- 安装包
$ composer require frengky/laravel-auditable
- 将服务提供者添加到您的
config/app.php
Frengky\Auditable\ServiceProvider::class
使用
将 Auditable 特性用于您的模型
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class YourModel extends Model { use Frengky\Auditable\Auditable; } ?>
现在您可以在每次使用模型进行更改时调用特性方法
// After creating new record $yourModel = YourModel::create(['title' => 'Foo']); $yourModel->auditCreating(); // Before saving updated record $yourModel->auditUpdating(); $yourModel->save(); // After deleting a record $yourModel->destroy($id); $yourModel->auditDeleting();