skore-labs/laravel-auditable
最新稳定版本:3.1.1
Composer 安装命令:
composer require skore-labs/laravel-auditable
包简介
Simple audit for users that performs actions to your Eloquent models
README 文档
README
Audit the users that performs actions to your application models
Status
Getting started
composer require skore-labs/laravel-auditable
And write this on the models you want to have auditables:
<?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']; }
And this is how it should look like in your migration file:
<?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'); } }
Note: If you wanna remove it on the down method of your migrations, you can use dropAuditables.
public function down() { Schema::table('posts', function (Blueprint $table) { $table->dropAuditables(); // or if has softDeletes (deleted_at column): $table->dropAuditables(true); }); }
Methods
These are all the relationships that the Auditable trait provides to your model:
$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
Support
This and all of our Laravel packages follows as much as possibly can the LTS support of Laravel.
Read more: https://laravel.com/docs/master/releases#support-policy
Credits
- Ruben Robles (@d8vjork)
- Skore (https://www.getskore.com/)
- And all the contributors
统计信息
- 总下载量: 554
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-03-12