Auditable

Auditable

Simplest Auditable for Laravel Eloquent/Model.

Moamen Eltouny (Raggi)
PHP Version : >= 7.2 Laravel Version : >= 6.0 License Support
Source Packagist Version Packagist Downloads

Install

Install the latest version using Composer

composer require pharaonic/laravel-auditable
Usage

Create auditable columns on the table

Just add one of this lines to your Migration file.

// created_by, created_at
// updated_by, updated_at
$table->auditable();

// created_by, created_at
// updated_by, updated_at
// deleted_by, deleted_at
$table->auditableWithSoftDeletes();

Inclusion

Including Auditable in the model (with/without SoftDeletes).

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Pharaonic\Laravel\Audits\Auditable;

class Article extends Model
{
    use Auditable;
    ...
}

How To Use

Getting created_by, updated_by and delelted_by Object (user).

// Creating
$article = Article::create(['title' => 'Moamen Eltouny']);
echo $article->created_at->isoFormat('LLLL');
echo $article->created_by->name;

// Updating
$article = Article::first();
echo $article->updated_at->isoFormat('LLLL');
echo $article->updated_by->name;

// Deleting (ONLY WITH SoftDeletes)
$article->delete();
$article = Article::withTrashed()->first();
echo $article->deleted_at->isoFormat('LLLL');
echo $article->deleted_at->name;