Record created by, updated by and deleted by on Eloquent models automatically.
MIT License
Record created by, updated by and deleted by (if SoftDeletes added) on Eloquent models automatically.
composer require quarks/laravel-auditors
In your migration classes, add the auditor columns to your table as below:
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->auditors();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropAuditors();
});
}
Then add the HasAuditors
trait your model classes as follows:
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Quarks\Laravel\Auditors\HasAuditors;
class User extends Authenticatable
{
use HasAuditors;
}
From now onwards, createdBy
, updatedBy
and deletedBy
relations on this model will automatically be saved on
created
, updated
and deleted
model events respectively.
See LICENSE file.