A laravel package that allows you to track and log nested changes applied on your (models, and their relations) using a single Trait
You can install the package via composer:
composer require mouadziani/laravel-model-trackable
- 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();
Currently this package can't track hasMany, ManyToMany or MorphMany relations
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email mouad.ziani1997@gmail.com instead of using the issue tracker.
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