skore-labs / laravel-auditable
审计执行您应用程序模型操作的用户
2.6.0
2024-05-24 11:40 UTC
Requires
- php: ^8.0
- illuminate/database: ^9.0 || ^10.0 || ^11.0
- illuminate/support: ^9.0 || ^10.0 || ^11.0
Requires (Dev)
- larastan/larastan: ^2.0
- orchestra/testbench: ^7.0 || ^8.0 || ^9.0
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^9.0 || ^10.0
README
审计执行您应用程序模型操作的用户
状态
入门指南
composer require skore-labs/laravel-auditable
然后在您希望具有可审计功能的模型上写入以下内容
<?php namespace SkoreLabs\LaravelAuditable\Tests\Fixtures; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use SkoreLabs\LaravelAuditable\Traits\Auditable; class Post extends Model { use Auditable; // Add this one and it will auto-detect for the deletedBy // use SoftDeletes; /** * The attributes that should be visible in serialization. * * @var array */ protected $visible = ['title', 'content']; }
在您的迁移文件中应该看起来像这样
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class CreatePostsTestTable extends Migration { public function up() { Schema::create('posts', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('title'); $table->text('content'); $table->timestamps(); $table->softDeletes(); $table->auditables(); // or if has softDeletes (deleted_at column): $table->auditables(true); // also you might want to rename the users table: $table->auditables(true, 'my_users_table'); }); } public function down() { Schema::dropIfExists('posts'); } }
注意:如果您想在迁移的down
方法中删除它,您可以使用dropAuditables
。
public function down() { Schema::table('posts', function (Blueprint $table) { $table->dropAuditables(); // or if has softDeletes (deleted_at column): $table->dropAuditables(true); }); }
方法
这些都是Auditable
特质为您的模型提供的关系
$post = Post::first(); $post->createdBy; // Author of the post $post->updatedBy; // Author of the last update of the post $post->deletedBy; // Author of the deletion of the post $post->author; // Alias for createdBy
支持
这个和我们的所有Laravel包都尽可能地遵循Laravel的LTS支持。
阅读更多: https://laravel.net.cn/docs/master/releases#support-policy
致谢
- Ruben Robles (@d8vjork)
- Skore (https://www.getskore.com/)
- 以及所有贡献者