luissantiago / elogquent
Elogquent listens events on Eloquent models and records every configured attribute change in a separate history table
Fund package maintenance!
luissantiago
Requires
- php: ^8.2
- laravel/framework: 11.*
- laravel/prompts: ^0.3.5
Requires (Dev)
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.22
- orchestra/testbench: ^10.0.0||^9.0.0||^8.22.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.3||^2.0
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
- vimeo/psalm: ^6.10
This package is auto-updated.
Last update: 2025-05-05 17:56:48 UTC
README
Elogquent is a Laravel package that automatically tracks and stores all changes made to your Eloquent models. It provides a complete history of modifications, allowing you to restore previous states of your models.
Preview of restore:
Features
- 🔄 Automatic tracking of model changes
- 📝 Configurable attribute inclusion/exclusion
- 🔍 Detailed change history
- ⏮️ Model state restoration
- 🧹 Duplicate change removal
- 👤 User attribution for changes
- 🛡️ Queue operations
Installation
You can install the package via composer:
composer require elogquent/elogquent
Install the package:
php artisan elogquent:install
Run the migrations:
php artisan migrate
Usage
Basic Usage
Add the Elogquent
trait to your model and any changes to your model will be automatically tracked:
use Elogquent\Traits\Elogquent; use Illuminate\Database\Eloquent\Model; class Post extends Model { use Elogquent; }
Accessing Model Changes History
You can access the change history through the allChanges
relationship:
$post = Post::find(1); $changes = $post->allChanges;
Restoring Previous States
Restore a model to a previous state:
$modelChange = ElogquentEntry::find(1); $modelChange->restore();
You can also use the artisan command:
php artisan elogquent:restore-changes
Configuration
Below are the key options you can configure in the elogquent.php
configuration file:
⚙️ 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’s default |
📋 Column Filtering
Option | Description |
---|---|
included_columns |
List of specific columns to track. If empty, all are tracked (except excluded). |
excluded_columns |
Columns to ignore (e.g., sensitive or irrelevant ones). Defaults include:password , remember_token , api_token , secret , token , updated_at |
🧹 History Optimization
Option | Description |
---|---|
remove_previous_duplicates |
Avoid logging identical consecutive states. Keeps only the latest. |
📦 Change Limits
Option | Description |
---|---|
changes_limit |
Maximum number of total stored changes globally. |
model_changes_limit |
Set limits per model class (overrides global). Example: App\Models\Post::class => 100 |
🧵 Queue Settings
Option | Description | Default |
---|---|---|
queue.delay |
Delay (in seconds) before processing updates. | 0 |
queue.connection |
The queue connection to use. | Laravel’s default (queue.default ) |
queue.queue |
Name of the queue to handle change jobs. | null |
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see License File for more information.
Credits
Support
For support, please open an issue in the GitHub repository or contact soyluissantiagotorres@gmail.com