quarks/laravel-auditors

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

1.2.1 2022-01-08 18:50 UTC

This package is auto-updated.

Last update: 2024-04-08 23:50:26 UTC


README

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

Latest Version Downloads PHP Version License

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.