PHPackages                             poldiwa/revisionable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. poldiwa/revisionable

AbandonedLibrary[Database &amp; ORM](/categories/database)

poldiwa/revisionable
====================

Keep a revision history for your models without thinking, created as a package for use with Laravel

2.0.1(7y ago)013MITPHPPHP ^7.1.3

Since Apr 8Pushed 7y ago1 watchersCompare

[ Source](https://github.com/poldiwa/revisionable)[ Packagist](https://packagist.org/packages/poldiwa/revisionable)[ Docs](http://github.com/venturecraft/revisionable)[ RSS](/packages/poldiwa-revisionable/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (2)Versions (49)Used By (0)

[![Revisionable](https://camo.githubusercontent.com/7169816f5903c1456c19e4d7711cf2120ce36739725d258901af0cfe37070305/687474703a2f2f76656e7475726563726166742e636f6d2e61752f77702d636f6e74656e742f75706c6f6164732f323031352f30392f5245564953494f4e41424c452e706e67)](https://camo.githubusercontent.com/7169816f5903c1456c19e4d7711cf2120ce36739725d258901af0cfe37070305/687474703a2f2f76656e7475726563726166742e636f6d2e61752f77702d636f6e74656e742f75706c6f6164732f323031352f30392f5245564953494f4e41424c452e706e67)

[![Laravel 4.x](https://camo.githubusercontent.com/1bd8193faffef3fdd0bb8a107fb03ed6caee25ec4277a5be16744f280951ccd7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d342e782d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](http://laravel.com)[![Laravel 5.2](https://camo.githubusercontent.com/587f825d686f4cf73655f19031afb8dfa137c3dd9cd71d1b42edeb4af56ab366/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d352e782d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](http://laravel.com)[![Latest Version](https://camo.githubusercontent.com/ab51ccc5b490d172a27288b247e76db31397e9e3749634539d021bd49d632272/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f76656e7475726563726166742f7265766973696f6e61626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/venturecraft/revisionable)[![Downloads](https://camo.githubusercontent.com/7a4137b04a7a337ad67dab7832a51cc02f396ad4255a0bbb8ac8a25ad13b1359/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f76656e7475726563726166742f7265766973696f6e61626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/venturecraft/revisionable)[![License](https://camo.githubusercontent.com/30597ff9a350144f03bffdd9183e16468e0b3ca1193e1d08591d992622738d55/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://tldrlegal.com/license/mit-license)

Wouldn't it be nice to have a revision history for any model in your project, without having to do any work for it. By simply extending revisionable from your model, you can instantly have just that, and be able to display a history similar to this:

- Chris changed title from 'Something' to 'Something else'
- Chris changed category from 'News' to 'Breaking news'
- Matt changed category from 'Breaking news' to 'News'

So not only can you see a history of what happened, but who did what, so there's accountability.

Revisionable is a laravel package that allows you to keep a revision history for your models without thinking. For some background and info, [see this article](http://www.chrisduell.com/blog/development/keeping-revisions-of-your-laravel-model-data/)

Working with 3rd party Auth / Eloquent extensions
-------------------------------------------------

[](#working-with-3rd-party-auth--eloquent-extensions)

Revisionable has support for Auth powered by

- [**Sentry by Cartalyst**](https://cartalyst.com/manual/sentry).
- [**Sentinel by Cartalyst**](https://cartalyst.com/manual/sentinel).

Revisionable can also now be used [as a trait](#the-new-trait-based-implementation), so your models can continue to extend Eloquent, or any other class that extends Eloquent (like [Ardent](https://github.com/laravelbook/ardent)).

Installation
------------

[](#installation)

Revisionable is installable via [composer](http://getcomposer.org/doc/00-intro.md), the details are on [packagist, here.](https://packagist.org/packages/venturecraft/revisionable)

Add the following to the `require` section of your projects composer.json file:

```
"venturecraft/revisionable": "1.*",
```

Run composer update to download the package

```
php composer.phar update

```

Finally, you'll also need to run migration on the package (Laravel 5.x)

```
php artisan migrate --path=vendor/venturecraft/revisionable/src/migrations

```

For Laravel 4.x users:

```
php artisan migrate --package=venturecraft/revisionable

```

> If you're going to be migrating up and down completely a lot (using `migrate:refresh`), one thing you can do instead is to copy the migration file from the package to your `app/database` folder, and change the classname from `CreateRevisionsTable` to something like `CreateRevisionTable` (without the 's', otherwise you'll get an error saying there's a duplicate class)

> `cp vendor/venturecraft/revisionable/src/migrations/2013_04_09_062329_create_revisions_table.php app/database/migrations/`

Docs
----

[](#docs)

- [Implementation](#intro)
- [More control](#control)
- [Format output](#formatoutput)
- [Load revision history](#loadhistory)
- [Display history](#display)
- [Contributing](#contributing)
- [Having troubles?](#faq)

Implementation
--------------

[](#implementation)

### The new, trait based implementation

[](#the-new-trait-based-implementation)

For any model that you want to keep a revision history for, include the revisionable namespace and use the `RevisionableTrait` in your model, e.g., If you are using another bootable trait the be sure to override the boot method in your model;

```
namespace MyApp\Models;

class Article extends Eloquent {
    use \Venturecraft\Revisionable\RevisionableTrait;

    public static function boot()
    {
        parent::boot();
    }
}
```

> Being a trait, revisionable can now be used with the standard Eloquent model, or any class that extends Eloquent, like [Ardent](https://github.com/laravelbook/ardent) for example.

> Traits require PHP &gt;= 5.4

### Legacy class based implementation

[](#legacy-class-based-implementation)

> The new trait based approach is backwards compatible with existing installations of Revisionable. You can still use the below installation instructions, which essentially is extending a wrapper for the trait.

For any model that you want to keep a revision history for, include the revisionable namespace and extend revisionable instead of eloquent, e.g.,

```
use Venturecraft\Revisionable\Revisionable;

namespace MyApp\Models;

class Article extends Revisionable { }
```

Note that it also works with namespaced models.

### Implementation notes

[](#implementation-notes)

If needed, you can disable the revisioning by setting `$revisionEnabled` to false in your model. This can be handy if you want to temporarily disable revisioning, or if you want to create your own base model that extends revisionable, which all of your models extend, but you want to turn revisionable off for certain models.

```
namespace MyApp\Models;

class Article extends Eloquent {
    use Venturecraft\Revisionable\RevisionableTrait;

    protected $revisionEnabled = false;
}
```

You can also disable revisioning after X many revisions have been made by setting `$historyLimit` to the number of revisions you want to keep before stopping revisions.

```
namespace MyApp\Models;

class Article extends Eloquent {
    use Venturecraft\Revisionable\RevisionableTrait;

    protected $revisionEnabled = true;
    protected $historyLimit = 500; //Stop tracking revisions after 500 changes have been made.
}
```

In order to maintain a limit on history, but instead of stopping tracking revisions if you want to remove old revisions, you can accommodate that feature by setting `$revisionCleanup`.

```
namespace MyApp\Models;

class Article extends Eloquent {
    use Venturecraft\Revisionable\RevisionableTrait;

    protected $revisionEnabled = true;
    protected $revisionCleanup = true; //Remove old revisions (works only when used with $historyLimit)
    protected $historyLimit = 500; //Maintain a maximum of 500 changes at any point of time, while cleaning up old revisions.
}
```

### Storing soft deletes

[](#storing-soft-deletes)

By default, if your model supports soft deletes, revisionable will store this and any restores as updates on the model.

You can choose to ignore deletes and restores by adding `deleted_at` to your `$dontKeepRevisionOf` array.

To better format the output for `deleted_at` entries, you can use the `isEmpty` formatter (see [Format output](#format-output) for an example of this.)

### Storing creations

[](#storing-creations)

By default the creation of a new model is not stored as a revision. Only subsequent changes to a model is stored.

If you want to store the creation as a revision you can override this behavior by setting `revisionCreationsEnabled` to `true` by adding the following to your model:

```
protected $revisionCreationsEnabled = true;
```

More control
------------

[](#more-control)

No doubt, there'll be cases where you don't want to store a revision history only for certain fields of the model, this is supported in two different ways. In your model you can either specifiy which fields you explicitly want to track and all other fields are ignored:

```
protected $keepRevisionOf = array(
    'title'
);
```

Or, you can specify which fields you explicitly don't want to track. All other fields will be tracked.

```
protected $dontKeepRevisionOf = array(
    'category_id'
);
```

> The `$keepRevisionOf` setting takes precendence over `$dontKeepRevisionOf`

### Events

[](#events)

Every time a model revision is created an event is fired. You can listen for `revisionable.created`,
`revisionable.saved` or `revisionable.deleted`.

```
// app/Providers/EventServiceProviders.php
public function boot(DispatcherContract $events)
{
    parent::boot($events);

    $events->listen('revisionable.*', function($model, $revisions) {
        // Do something with the revisions or the changed model.
        dd($model, $revisions);
    });
}
```

Format output
-------------

[](#format-output)

> You can continue (and are encouraged to) use `eloquent accessors` in your model to set the output of your values, see the [laravel docs for more information on accessors](http://laravel.com/docs/eloquent-mutators#accessors-and-mutators)The below documentation is therefor deprecated

In cases where you want to have control over the format of the output of the values, for example a boolean field, you can set them in the `$revisionFormattedFields` array in your model. e.g.,

```
protected $revisionFormattedFields = array(
    'title'  => 'string:%s',
    'public' => 'boolean:No|Yes',
    'modified' => 'datetime:m/d/Y g:i A',
    'deleted_at' => 'isEmpty:Active|Deleted'
);
```

You can also override the field name output using the `$revisionFormattedFieldNames` array in your model, e.g.,

```
protected $revisionFormattedFieldNames = array(
    'title' => 'Title',
    'small_name' => 'Nickname',
    'deleted_at' => 'Deleted At'
);
```

This comes into play when you output the revision field name using `$revision->fieldName()`

### String

[](#string)

To format a string, simply prefix the value with `string:` and be sure to include `%s` (this is where the actual value will appear in the formatted response), e.g.,

```
string:%s

```

### Boolean

[](#boolean)

Booleans by default will display as a 0 or a 1, which is pretty bland and won't mean much to the end user, so this formatter can be used to output something a bit nicer. Prefix the value with `boolean:` and then add your false and true options separated by a pipe, e.g.,

```
boolean:No|Yes

```

### DateTime

[](#datetime)

DateTime by default will display as Y-m-d H:i:s. Prefix the value with `datetime:` and then add your datetime format, e.g.,

```
datetime:m/d/Y g:i A

```

### Is Empty

[](#is-empty)

This piggy backs off boolean, but instead of testing for a true or false value, it checks if the value is either null or an empty string.

```
isEmpty:No|Yes

```

This can also accept `%s` if you'd like to output the value, something like the following will display 'Nothing' if the value is empty, or the actual value if something exists:

```
isEmpty:Nothing|%s

```

Load revision history
---------------------

[](#load-revision-history)

To load the revision history for a given model, simply call the `revisionHistory` method on that model, e.g.,

```
$article = Article::find($id);
$history = $article->revisionHistory;
```

Displaying history
------------------

[](#displaying-history)

For the most part, the revision history will hold enough information to directly output a change history, however in the cases where a foreign key is updated we need to be able to do some mapping and display something nicer than `plan_id changed from 3 to 1`.

To help with this, there's a few helper methods to display more insightful information, so you can display something like `Chris changed plan from bronze to gold`.

The above would be the result from this:

```
@foreach($account->revisionHistory as $history )
    {{ $history->userResponsible()->first_name }} changed {{ $history->fieldName() }} from {{ $history->oldValue() }} to {{ $history->newValue() }}
@endforeach
```

If you have enabled revisions of creations as well you can display it like this:

```
@foreach($resource->revisionHistory as $history)
  @if($history->key == 'created_at' && !$history->old_value)
    {{ $history->userResponsible()->first_name }} created this resource at {{ $history->newValue() }}
  @else
    {{ $history->userResponsible()->first_name }} changed {{ $history->fieldName() }} from {{ $history->oldValue() }} to {{ $history->newValue() }}
  @endif
@endforeach
```

### userResponsible()

[](#userresponsible)

Returns the User that was responsible for making the revision. A user model is returned, or null if there was no user recorded.

The user model that is loaded depends on what you have set in your `config/auth.php` file for the `model` variable.

### fieldName()

[](#fieldname)

Returns the name of the field that was updated, if the field that was updated was a foreign key (at this stage, it simply looks to see if the field has the suffix of `_id`) then the text before `_id` is returned. e.g., if the field was `plan_id`, then `plan` would be returned.

> Remember from above, that you can override the output of a field name with the `$revisionFormattedFieldNames` array in your model.

### identifiableName()

[](#identifiablename)

This is used when the value (old or new) is the id of a foreign key relationship.

By default, it simply returns the ID of the model that was updated. It is up to you to override this method in your own models to return something meaningful. e.g.,

```
use Venturecraft\Revisionable\Revisionable;

class Article extends Revisionable
{
    public function identifiableName()
    {
        return $this->title;
    }
}
```

### oldValue() and newValue()

[](#oldvalue-and-newvalue)

Get the value of the model before or after the update. If it was a foreign key, identifiableName() is called.

### Unknown or invalid foreign keys as revisions

[](#unknown-or-invalid-foreign-keys-as-revisions)

In cases where the old or new version of a value is a foreign key that no longer exists, or indeed was null, there are two variables that you can set in your model to control the output in these situations:

```
protected $revisionNullString = 'nothing';
protected $revisionUnknownString = 'unknown';
```

### disableRevisionField()

[](#disablerevisionfield)

Sometimes temporarily disabling a revisionable field can come in handy, if you want to be able to save an update however don't need to keep a record of the changes.

```
$object->disableRevisionField('title'); // Disables title
```

or:

```
$object->disableRevisionField(array('title', 'content')); // Disables title and content
```

Contributing
------------

[](#contributing)

Contributions are encouraged and welcome; to keep things organised, all bugs and requests should be opened in the GitHub issues tab for the main project, at [venturecraft/revisionable/issues](https://github.com/venturecraft/revisionable/issues)

All pull requests should be made to the develop branch, so they can be tested before being merged into the master branch.

Having troubles?
----------------

[](#having-troubles)

If you're having troubles with using this package, odds on someone else has already had the same problem. Two places you can look for common answers to your problems are:

- [StackOverflow revisionable tag](http://stackoverflow.com/questions/tagged/revisionable?sort=newest&pageSize=50)
- [GitHub Issues](https://github.com/VentureCraft/revisionable/issues?page=1&state=closed)

> If you do prefer posting your questions to the public on StackOverflow, please use the 'revisionable' tag.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 72.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~49 days

Recently: every ~286 days

Total

45

Last Release

2625d ago

Major Versions

1.28.0 → 2.0.02019-03-02

PHP version history (2 changes)1.0.0PHP &gt;=5.3.0

2.0.0PHP ^7.1.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/40347d0802fce65e19f0bf8d64ad3f82e67189db0a92c2b92ad10141984b5b69?d=identicon)[poldiwa](/maintainers/poldiwa)

---

Top Contributors

[![duellsy](https://avatars.githubusercontent.com/u/330539?v=4)](https://github.com/duellsy "duellsy (180 commits)")[![sniper7kills](https://avatars.githubusercontent.com/u/5902574?v=4)](https://github.com/sniper7kills "sniper7kills (10 commits)")[![stierler](https://avatars.githubusercontent.com/u/1009070?v=4)](https://github.com/stierler "stierler (8 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (6 commits)")[![anarchocoder](https://avatars.githubusercontent.com/u/8037302?v=4)](https://github.com/anarchocoder "anarchocoder (6 commits)")[![pti-paul](https://avatars.githubusercontent.com/u/61076828?v=4)](https://github.com/pti-paul "pti-paul (5 commits)")[![argia-andreas](https://avatars.githubusercontent.com/u/9297340?v=4)](https://github.com/argia-andreas "argia-andreas (4 commits)")[![RDelorier](https://avatars.githubusercontent.com/u/2295675?v=4)](https://github.com/RDelorier "RDelorier (3 commits)")[![trizz](https://avatars.githubusercontent.com/u/832056?v=4)](https://github.com/trizz "trizz (2 commits)")[![paulofreitas](https://avatars.githubusercontent.com/u/667360?v=4)](https://github.com/paulofreitas "paulofreitas (2 commits)")[![rhynodesigns](https://avatars.githubusercontent.com/u/2198266?v=4)](https://github.com/rhynodesigns "rhynodesigns (2 commits)")[![miclf](https://avatars.githubusercontent.com/u/3188746?v=4)](https://github.com/miclf "miclf (1 commits)")[![mmawdsleyhallnet](https://avatars.githubusercontent.com/u/62430199?v=4)](https://github.com/mmawdsleyhallnet "mmawdsleyhallnet (1 commits)")[![orthographic-pedant](https://avatars.githubusercontent.com/u/14522744?v=4)](https://github.com/orthographic-pedant "orthographic-pedant (1 commits)")[![th3hamburgler](https://avatars.githubusercontent.com/u/180245?v=4)](https://github.com/th3hamburgler "th3hamburgler (1 commits)")[![davidavz](https://avatars.githubusercontent.com/u/6774576?v=4)](https://github.com/davidavz "davidavz (1 commits)")[![rajivseelam](https://avatars.githubusercontent.com/u/1103649?v=4)](https://github.com/rajivseelam "rajivseelam (1 commits)")[![JosephSilber](https://avatars.githubusercontent.com/u/1403741?v=4)](https://github.com/JosephSilber "JosephSilber (1 commits)")[![ivelrrat](https://avatars.githubusercontent.com/u/5580032?v=4)](https://github.com/ivelrrat "ivelrrat (1 commits)")[![rickmills](https://avatars.githubusercontent.com/u/103707?v=4)](https://github.com/rickmills "rickmills (1 commits)")

---

Tags

laravelmodelrevisionhistoryardent

### Embed Badge

![Health badge](/badges/poldiwa-revisionable/health.svg)

```
[![Health](https://phpackages.com/badges/poldiwa-revisionable/health.svg)](https://phpackages.com/packages/poldiwa-revisionable)
```

###  Alternatives

[venturecraft/revisionable

Keep a revision history for your models without thinking, created as a package for use with Laravel

2.6k6.6M51](/packages/venturecraft-revisionable)[mpociot/versionable

Allows to create Laravel 4 / 5 / 6 / 7 / 8 / 9 / 10 / 11 Model versioning and restoring

7841.1M6](/packages/mpociot-versionable)[panoscape/history

Eloquent model history tracking for Laravel

162130.3k](/packages/panoscape-history)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
