Download the PHP package czim/laravel-modelcomparer without Composer
On this page you can find all versions of the php package czim/laravel-modelcomparer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download czim/laravel-modelcomparer
More information about czim/laravel-modelcomparer
Files in czim/laravel-modelcomparer
Package laravel-modelcomparer
Short Description Performs a deep-nested comparison of a model's before/after state.
License MIT
Homepage https://github.com/czim/laravel-modelcomparer
Informations about the package laravel-modelcomparer
Laravel Model Comparer
This model comparer is a tool to make it easy to collect, log and report changes made to Eloquent models and their relations.
It's easy enough to compare model attributes before and after (or using getDirty()
, during) updates for a single Eloquent model.
Unfortunately, it is arduous to track updates while updating deeply nested relational model structures.
With this package, it's as simple as loading in the model before making changes, then loading it in again after. The comparer instance tracks the changes and offers the means to create concise changelogs.
Version Compatibility
Laravel | Package | PHP Version |
---|---|---|
5.3 and older | 0.9 | |
5.4 to 5.7 | 1.4 | |
5.8 | 1.5 | |
5.8, 6.0+ | 2.0 | |
9.0+ | 3.0 | 8.1+ |
Install
Via Composer
If you're not using auto-discovery (or are installing a version older than 3.0),
add the service provider in your config/app.php
config.
Usage
- Initialize a comparer instance
- Before making changes, set the before state on the comparer by passing in the model
- Make your changes to anything related to the model
- Run the comparison by passing in the model again
The result is an comparison information object that stores all the changes and offers means for easy logging.
To Do
-
Add singleton with facade for easy tracking of changes
- would use the model's class & key to keep track of before states and allow setting after states
- might even be done using an observer pattern
- note: not recommended for long running processes, unless cleanup methods are used to keep memory load small
- Better change tracking for related models
- Track before state index by model class & key in the comparer
- And, singleton should delegate this to currently active comparers
- Track changes of a model when it is still via-via related before AND after (but for a different intermediary relation)
- Allow manually 'loading in' before state for a to-be related model
- Track before state index by model class & key in the comparer
Contributing
Please see CONTRIBUTING for details.
Credits
- Coen Zimmerman
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-modelcomparer with dependencies
ext-json Version *