Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/MouadZIANI/laravel-model-trackable
🔍 Laravel package that allows you to track and log nested changes applied on your models
https://github.com/MouadZIANI/laravel-model-trackable
laravel laravel-package php
Last synced: about 1 month ago
JSON representation
🔍 Laravel package that allows you to track and log nested changes applied on your models
- Host: GitHub
- URL: https://github.com/MouadZIANI/laravel-model-trackable
- Owner: mouadziani
- License: mit
- Created: 2020-11-20T19:08:22.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-07-31T03:51:16.000Z (over 2 years ago)
- Last Synced: 2024-08-02T13:22:04.385Z (4 months ago)
- Topics: laravel, laravel-package, php
- Language: PHP
- Homepage:
- Size: 118 KB
- Stars: 58
- Watchers: 3
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-morocco - laravel-model-trackable - model-trackable.svg?style=social)](https://github.com/MouadZIANI/laravel-model-trackable/stargazers) - A laravel package that allows you to track and log nested changes applied on your models. by [@mouadziani](https://github.com/mouadziani) (Uncategorized / Uncategorized)
README
[![Latest Version on Packagist](https://img.shields.io/packagist/v/mouadziani/laravel-model-trackable.svg?style=flat-square)](https://packagist.org/packages/mouadziani/laravel-model-trackable)
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:
```bash
composer require mouadziani/laravel-model-trackable
```## Simple Usage
- Firstly you have to apply trackable trait on your model
``` php
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
``` phpuse 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
``` php
$model = ModelName::update([
...
]);// Get list of changed attributes
$model->getChangedAttributes();
```## Disclaimer
Currently this package can't track hasMany, ManyToMany or MorphMany relations### Testing
``` bash
composer test
```### Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
### Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
## Credits
- [Mouad ZIANI](https://github.com/mouadziani)
- [All Contributors](../../contributors)## Licence
This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/mouadziani/laravel-model-trackable) 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