Apply the trait HasRevisions to any model to be able to: View a history of changes, revert to previous versions of the model and allow for easy moderation of changes before persisting to the database.
wearesweet/laravel-revisonable is a Laravel package for apply the trait hasrevisions to any model to be able to: view a history of changes, revert to previous versions of the model and allow for easy moderation of changes before persisting to the database..
It currently has 2 GitHub stars and 0 downloads on Packagist.
Install it with composer require wearesweet/laravel-revisonable.
Discover more Laravel packages by wearesweet
or browse all Laravel packages to compare alternatives.
Last updated
Apply the trait HasRevisions to any model to be able to: View a history of changes, revert to previous versions of the model and allow for easy moderation of changes before persisting to the database.
We Are Sweet is a small but mighty wb agency providing design development and consultancy services to a wide range of clients.
This package requires PHP 7.6 and Laravel 6 or higher.
Run
$ composer require wearesweet/laravel-revisionable
Add the HasRevisions trait to your model(s).
class User {
use WeAreSweet\LaravelRevisionable\Traits\HasRevisions;
}
Override revisionableAttributes so that it returns an array of attributes you want to allow revisions for.
If using revisionableAttributes in conjunction with persistRevisions, attributes in your array will be stored as a revision which can later be persisted (approved) and all other attributes not in the array will be persisted imminently.
class User {
use WeAreSweet\LaravelRevisionable\Traits\HasRevisions;
public function revisionableAttributes()
{
return 'name';
}
}
You can tell your models not to save directly to the model and instead save the data in revisions which can be applied to the model later.
This is useful for storing draft states of your models or for moderating and approving changes.
To do this, add the method persistRevisions to your class and have it return false.
class User {
use WeAreSweet\LaravelRevisionable\Traits\HasRevisions;
public function persistRevisions()
{
return false;
}
}
App\User::first()->revisions;
App\User::first()->revisions()->pending()->get();
App\User::first()->revisions->first()->approve();
App\User::first()->pendingRevisions();
{
"user":{
"revisions": [
{
"date": "2020",
"data": {"name": "Ben"}
},
{
"date": "2010",
"data": {"name": "Neb", "age": 23}
}
]
}
}
{
"name": "Ben",
"age": 23
}
App\User::first()->approveAllRevisions();
Run the tests with:
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.