asseco-voice / laravel-blueprint-audit
Laravel 对额外蓝图方法的支持
v2.0.0
2023-08-07 10:07 UTC
Requires
- php: ^8.1
- laravel/framework: ^10.0
Requires (Dev)
- fakerphp/faker: ^1.9.1
- mockery/mockery: ^1.4.4
- orchestra/testbench: ^8.5
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-09-07 13:06:25 UTC
README
蓝图审计
该仓库的目的是为了提供迁移的额外方法。
安装
使用 composer require asseco-voice/laravel-blueprint-audit
安装包。服务提供程序将自动注册。
使用
在迁移中调用 $table->audit()
以获取这些属性
$this->timestamp('created_at')->nullable(); $this->string('created_by')->nullable(); $this->string('creator_type')->nullable(); $this->timestamp('updated_at')->nullable(); $this->string('updated_by')->nullable(); $this->string('updater_type')->nullable();
或调用 $table->softDeleteAudit()
以获取额外属性
$this->timestamp('deleted_at')->nullable(); $this->string('deleted_by')->nullable(); $this->string('deleter_type')->nullable();
如果你使用第一个,请在你的模型上添加 Audit
特性,对于第二个,添加 SoftDeleteAudit
特性以使这些属性自动填充。
_type
字段存在是为了支持如果你有多个实体类型可以执行资源上的操作(例如 service
或 user
)。
你可以通过发布配置并实现自己的提取器类来修改如何提取 ID 和类型。确保你的扩展类实现了 Extractor
接口。使用命令 php artisan vendor:publish --tag=asseco-blueprint-audit
。
运行时选择器
有一个辅助类可以让你在运行时选择时间戳类型。所以你可以定义一个配置键,它将在迁移中使用,并选择要运行的迁移类型。
例如,有以下迁移
public function up() { Schema::create('matches', function (Blueprint $table) { // ... // some fields // ... MigrationMethodPicker::pick($table, config('your-config.timestamps')); }); }
配置值是 MigrationMethodPicker
类型之一,例如 'soft'
将评估你的迁移为
public function up() { Schema::create('matches', function (Blueprint $table) { // ... // some fields // ... $table->timestamps(); $table->softDeletes(); }); }