Skip to main content
Tutorial Free

Revisionable: package to log who did what and when in Laravel Models

October 25, 2016
2 min read
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.

Enjoyed This Tutorial?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.