luissantiago/elogquent

Listens to Eloquent model events and logs configured attribute changes into a history table.

v1.0.5 2025-05-11 19:19 UTC

This package is auto-updated.

Last update: 2025-05-29 13:41:24 UTC


README

Elogquent Logo

PHP Version Latest Version Total Downloads Tests Lint Coverage

Elogquent is a Laravel package that automatically tracks and stores all changes made to your Eloquent models.
It provides a complete audit trail and allows restoring models to previous states with ease.

Restore Preview

RestoreChanges Animation

Features

  • Automatic model change tracking
  • Configurable attribute inclusion/exclusion
  • Detailed change history per model
  • Restore previous model states
  • Duplicate change optimization
  • User attribution for changes
  • Supports queue-based processing

Installation

Install the package via Composer:

composer require luissantiago/elogquent

Publish config and install:

php artisan elogquent:install

Run the database migrations:

php artisan migrate

Usage

Add Trait to Your Model

use Elogquent\Traits\Elogquent;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use Elogquent;
}

Access Change History

$post = Post::find(1);
$changes = $post->allChanges;

Restore to a Previous State

$modelChange = ElogquentEntry::find(1);
$modelChange->restore();

Or use the artisan command:

php artisan elogquent:restore-changes

Configuration

Edit the elogquent.php config file for customization.

Basic Settings

Option Description Default
enabled Enable or disable Elogquent globally. true
store_user_id Store the authenticated user's ID with each change. true
database_connection The database connection used for change history. Laravel default

Column Filtering

Option Description
included_columns Specific columns to track. If empty, all columns are tracked (except excluded).
excluded_columns Columns to ignore (e.g. sensitive fields). Default: password, remember_token, api_token, secret, token, updated_at

History Optimization

Option Description
remove_previous_duplicates Prevent logging identical consecutive states. Keeps only the latest.

Change Limits

Option Description
changes_limit Global limit on total number of stored changes.
model_changes_limit Limit changes per model. Example: 'App\Models\Post::class' => 100

Queue Settings

Option Description Default
queue.delay Delay (in seconds) before processing updates. 0
queue.connection Queue connection to use. Laravel default (queue.default)
queue.queue Queue name for change jobs. null

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). See License File for more information.

Credits

Support

For support, open an issue in the GitHub repository or contact
soyluissantiagotorres@gmail.com