riorizkyrainey / lara-ced
This package automatically inserts/updates creator, editor and destroyer on your table.
Installs: 1 564
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^7.0
- illuminate/database: ^5.5
- illuminate/support: ^5.5
Requires (Dev)
- orchestra/testbench: ^3.4
- phpunit/phpunit: ^7.3
This package is auto-updated.
Last update: 2024-11-12 23:18:23 UTC
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.