Download the PHP package johannesschobel/laravel-revisionable without Composer
On this page you can find all versions of the php package johannesschobel/laravel-revisionable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download johannesschobel/laravel-revisionable
More information about johannesschobel/laravel-revisionable
Files in johannesschobel/laravel-revisionable
Package laravel-revisionable
Short Description Makes Laravel Models revisionable
License MIT
Informations about the package laravel-revisionable
JohannesSchobel/Laravel-Revisionable
Easy and conventient way to handle revisions of your models within the database.
- Handles the revisions in bulk - one entry covers all the created/updated fields, what makes it really easy to e.g., compare 2 given versions or get all the data changed during one single transaction.
Requirements
- This package requires PHP 5.4+
- Currently it works out of the box with Laravel5.4 + generic Illuminate Guard, tymon/jwt-auth OR cartalyst/sentry 2/sentinel 2
Usage (Laravel 5 basic example - see Customization below as well)
1. Download the package or require in your composer.json
:
2. Add the service provider to your app/config/app.php
:
3. Publish the package config file:
this will create config/revisionable.php
file, where you can adjust a few settings.
4. Run the migration in order to create the revisions table:
5. Add revisionable trait to the models you wish to keep track of:
And that's all to get you started!
Customization
The package offers a set of configuration options.
White-Listing Fields
If you would like to revision only specific fields of the model, you can define them like so:
This way, only the fields email
and name
are tracked and store as revision in the database. The default behaviour
is to revision all fields.
Disable Revisions
If you want to disable revisions for a specific model just add the following variables to your model
Revision Cleanup
You can further specify that you only want to clean up old revisions of a model. By doing so, you can further define, how many revisions of one model you would like to keep in your database (default is set to 20). Say, if you add the 21st revision, the first one is deleted.
You may customize this behaviour for each model by changing the variables
Rollback (aka load old revisions)
Of course, you can rollback to an old revision of your model. The Trait
added earlier (e.g., the Revisionable
trait)
already provides handy methods for you - so you don't need to worry about this.
You can either use the $model->rollbackToTimestamp($timestamp)
or $model->rollbackSteps($steps)
functions for this
purpose. Note that there is a configuration flag revisionable.rollback.cleanup
(default false
) that indicates,
whether the revisions rolled back should be deleted (true
) or not (false
).
Both functions return the rolled back model, which is already persisted in the database.