Download the PHP package temistocle1998/laravel-model-tracker without Composer
On this page you can find all versions of the php package temistocle1998/laravel-model-tracker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download temistocle1998/laravel-model-tracker
More information about temistocle1998/laravel-model-tracker
Files in temistocle1998/laravel-model-tracker
Package laravel-model-tracker
Short Description A Laravel package for tracking model changes, including old values, new values, and the user responsible for the changes
License MIT
Informations about the package laravel-model-tracker
Laravel Model Tracker
A lightweight Laravel package to track changes in your models. Automatically logs all changes, including old values, new values, and the user responsible for the changes.
Features
- Automatically tracks changes in any Eloquent model.
- Stores old and new values of updated fields.
- Logs the user who made the change (if authenticated).
- Provides easy integration with a simple trait.
- Configurable to exclude fields from tracking.
- Includes a migration to store logs in a
model_changes
table.
Requirements
- Laravel 8.x or 9.x
- PHP 7.4 or higher
Installation
-
Install via Composer:
-
Publish configuration and migration files:
-
Add the
TracksChanges
trait to your model:In any model where you want to track changes, simply include the
TracksChanges
trait:
Configuration
The package comes with a config file that can be customized to suit your needs. The configuration file can be found at config/tracker.php
.
Example Config:
Usage
Once the package is set up, any changes made to the models using the TracksChanges
trait will automatically be logged. The logs are stored in the model_changes
table.
Example of Change Logs
When a model is updated, the following log is created in the model_changes
table:
model_type | model_id | user_id | changes | created_at |
---|---|---|---|---|
App\Models\Product | 1 | 2 | {"name": {"old_value": "Old Name", "new_value": "New Name"}} | 2023-01-01 12:00:00 |
Retrieving Model Changes
You can fetch model changes using the ModelChange
model.
Displaying Changes in Your View
You can also display the changes in your views:
Contributing
Feel free to submit a pull request if you'd like to contribute to this package. All contributions are welcome!
License
This package is licensed under the MIT License. See the LICENSE file for details.