A short review of a package which is hugely popular but I’ve found it only recently. Quite a useful case – if you want to log all the changes to your data – who changed what and when, it’s pretty simple with Revisionable.
The usage is pretty simple:
- Install the package
- Run its migrations – basically it’s one table called “revisions”
- Add some code into a model you want to “follow”
Here’s my example of Model:
namespace App; use Illuminate\Database\Eloquent\Model; class Book extends Model { use \Venturecraft\Revisionable\RevisionableTrait; protected $fillable = ['title', 'description']; public static function boot() { parent::boot(); } }
And basically, that’s it. Whenever someone updates a database entry with Eloquent, like this:
$book = \App\Book::find(1); $book->update(['title' => 'bbb']);
You will get a new entry in database table revisions.
And then you can create a separate view to show that log more conveniently.
Of course, there are a lot of additional settings and functionality, like for example:
- History limit = X. Stop tracking revisions after 500 changes have been made
- $revisionCleanup = true; //Remove old revisions (works only when used with $historyLimit)
- Storing soft deletes
- Storing creations or not
In general, a really good package by Chris Duell. And I recommend you read full documentation on Github page here – a lot of interesting small things there.
Update: there’s another similar package by Marcel Pociot – called Versionable – check it out too.
use your revisionable data for more stuff
https://github.com/fico7489/laravel-revisionable-upgrade
Hi I used this package but it is not working on my laravel 5.5 project. Any thoughts?
From what I see, package author didn’t update anything for more than a year, with a lot of issues and pull requests. Shame.
finally he committed something 🙂