riorizkyrainey/lara-ced
Composer 安装命令:
composer require riorizkyrainey/lara-ced
包简介
This package automatically inserts/updates creator, editor and destroyer on your table.
README 文档
README
This package automatically inserts/updates creator, editor and destroyer on your table.
Requirements
- This package requires PHP 7.1+
- It works with Laravel 5.5 (and may work with earlier versions too).
Install via Composer
composer require riorizkyrainey/lara-ced
Usage
Update your model's migration and add created_by, updated_by and deleted_by field using the ced() blueprint macro.
Schema::create('article', function (Blueprint $table) { $table->increments('id'); $table->string('title', 100); $table->ced(); //add 'created_by', 'updated_by' and 'deleted_by' $table->timestamps(); });
or you can add one of the 3 columns.
Schema::create('article', function (Blueprint $table) { $table->increments('id'); $table->string('title', 100); $table->creator(); // Add created_by $table->editor(); // Add updated_by $table->destroyer(); // Add deleted_by $table->timestamps(); });
or with custom column name
Schema::create('article', function (Blueprint $table) { $table->increments('id'); $table->string('title', 100); $table->creator('seng_gawe'); // Add seng_gawe $table->editor('seng_edit'); // Add seng_edit $table->destroyer('seng_ndelet'); // Add seng_ndelet $table->timestamps(); });
Then use LaraCedTrait on your model.
namespace App; use LaraCed\LaraCedTrait; class Article extends Model { use LaraCedTrait; }
The following methods become available on your models to help retrieve the users creating, updating and deleting (if using SoftDeletes).
$model -> creator; // the user who created the model $model -> editor; // the user who last updated the model $model -> destroyer; // the user who deleted the model
If you want to define the created_by, updated_by, or deleted_by column names, add the following class constants to your model(s).
const CREATED_BY = 'created_by'; const UPDATED_BY = 'updated_by'; const DELETED_BY = 'deleted_by';
Dropping columns
You can drop auditable columns using dropCed() method.
Schema::table('articles', function (Blueprint $table) { $table->dropCed(); });
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 1.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-08-24