Versions
Prevents update conflicts using the optimistic lock pattern in Laravel.
This package can work independently of the Enso ecosystem.
For live examples and demos, you may visit laravel-enso.com
Installation
The package does not installed by default in Enso.
To install:
- add the package using composer
composer require laravel-enso/versions
- use the
Versions
trait on the models you want versioning on - ensure the models/tables have the required column, to hold the version
- add and set the
protected $versioningAttribute = 'version'
attribute on the versioned models
Features
- the package uses a column on your model to store the version (the column name is configurable)
- by using the
Versions
trait on a model, versioning is handled automatically - by default the trait sets the version to 1, just before the model is created
- the version attribute can be set by using
protected $versioningAttribute = 'customVersionAttribtue'
on the model - the trait can be used on models that already have records in the database, the versioning will start with the first retrieval of those models
- throws a
ConflictHttpException
if the version does not match on update
Contributions
are welcome. Pull requests are great, but issues are good too.
License
This package is released under the MIT license.