laravel-auditors

Record created by, updated by and deleted by on Eloquent models automatically.

MIT License

Downloads
16.7K
Stars
3
Committers
1

quarks/laravel-auditors

Record created by, updated by and deleted by (if SoftDeletes added) on Eloquent models automatically.

Installation

composer require quarks/laravel-auditors

Usage

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.

License

See LICENSE file.