mouadziani / laravel-model-trackable
A laravel package that allows you to tracker and log nested changes applied on your models and their relations using a single Trait
Requires
- illuminate/database: ~5.6.0|~5.7.0|~5.8.0|^6.0.0|^7.0.0|^8.0.0
- illuminate/events: ~5.6.0|~5.7.0|~5.8.0|^6.0.0|^7.0.0|^8.0.0
- illuminate/support: ^6.0 || ^7.0 || ^8.0
Requires (Dev)
- orchestra/testbench: ~3.6.0|~3.7.0|~3.8.0|^4.0|^5.0|^6.0
- phpunit/phpunit: ^7.0|^8.0
This package is not auto-updated.
Last update: 2025-03-15 12:52:43 UTC
README
A laravel package that allows you to track and log nested changes applied on your (models, and their relations) using a single Trait
Installation
You can install the package via composer:
composer require mouadziani/laravel-model-trackable
Simple Usage
- Firstly you have to apply trackable trait on your model
use LaravelModelTrackable\Traits\Trackable; class ModelName extends Model { use Trackable; // }
- In case you want to track the changes applied on your model's relationships, you need to add an attribute in your model called
$toBeLoggedRelations
which must contain an array of relationships like the example below
use LaravelModelTrackable\Traits\Trackable; class ModelName extends Model { use Trackable; public $toBeLoggedRelations = ['relation1', 'relation2']; }
- Then, you can get an array that should contains all changes applied on your model after every update
$model = ModelName::update([ ... ]); // Get list of changed attributes $model->getChangedAttributes();
Disclaimer
Currently this package can't track hasMany, ManyToMany or MorphMany relations
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email mouad.ziani1997@gmail.com instead of using the issue tracker.
Credits
Licence
This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.
featured_repository