Skip to content

sschlein/versionable

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Versionable

Easy to use Model versioning for Laravel 4 and Laravel 5

With this package you can create a history of the objects stored in your application. You just need to insert the VersionableTrait in each Model that you want to set under version control. All versions are stored in a new database table.

Examples

Store each change of

  • a product to roll back the changes later
  • a user to prevent that the user can set an old password when he has to create a new one every n weeks
  • a document to create a document history
  • a settings model where you need to know who did the changes

Installation

  • Add the following line to your require array of the composer.json file: "mpociot/versionable": "1.*"
  • Update your installation composer update
  • Run the migrations from this package php artisan migrate --package=mpociot/versionable

Implementation

Let the Models you want to set under version control use the VersionableTrait.

use VersionableTrait;

On each update of the Model a new version will be stored in the database.

To retrieve all stored versions as an array use the versions attribute on your model.

$model->versions;

To retrieve the model state of a version simply call the getModel method on the version object.

$model = $version->getModel();

Configuration

Versionable can be configured in the Model that uses the Trait. Simply add the configuration properties in your Model.

// do not store the content of these fields
public $dontVersionFields = [ 'last_login_date' ];

// do not create a new version if these fields change
protected $dontKeepRevisionOf = [ 'last_login_date' ];

About

Laravel 4 Model versioning made easy

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%