Revisionable now supports being used as a trait

One of the biggest requests that I would receive for my revisionable package was to allow it to work together with other packages like Ardent. Previously, the two could not work together as they were both fighting to be the class that your models would extend (each in turn, would extend eloquent). And since PHP doesn’t allow extending more than one class at a time, you had to pick one or the other.

I’m pleased to announce that as of today (with the help of a handful of willing testers) that the revisionable package is now useable as a full class, or as a trait. The choice is up to you.

This means you can now use it with ardent (or indeed, any other eloquent extending class).

If you’re unaware of revisionable, it is a laravel based package that allows you to extremely easily keep revisions of your models data.

Simply by extending (or now ‘using’) the revisionable class. A full history will be stored for you to report on, display, or do whatever else you wish.

e.g., if a user were to update their account details, revisionable will keep a record of what field was changed, what the previous value was, what they updated it to, by who, and when.

Since traits are only supported in PHP 5.4+, I’ve left support for using revisionable as a full class for backwards compatibility.

To see how to use revisionable as either a trait or a full extension, check out the new documentation here:

https://github.com/VentureCraft/revisionable/tree/develop#implementation

  • Aleksander Kalnoy

    Not a good idea to override `boot()` method since other traits might want to use it. I prefer to give it a unique name (like `bootRevisionable`) and call this method from the model’s `boot`. I use this approach for morphed relations.

    • http://www.subooa.com.au Chris Duell

      completely agree, and I’m open to alternatives to this where existing users of the package do not need to make any modifications to their models. Boot was the only way I could think to accomplish this at this stage. Thoughts?