luissantiago / elogquent
Listens to Eloquent model events and logs configured attribute changes into a history table.
Fund package maintenance!
luissantiago
Requires
- php: ^8.2 || ^8.3 || ^8.4
- illuminate/database: ^11.0 || ^12.0
- illuminate/support: ^11.0 || ^12.0
- laravel/prompts: ^0.2 || ^0.3
Requires (Dev)
- larastan/larastan: ^2.9 || ^3.0
- laravel/pint: ^1.22 || ^2.0
- orchestra/testbench: ^10.0 || ^11.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.0
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
This package is auto-updated.
Last update: 2025-05-29 13:41:24 UTC
README
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
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