PHPackages                             develoopin/versionable - 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. develoopin/versionable

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

develoopin/versionable
======================

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

3.1.5(5y ago)02531MITPHPPHP &gt;=7.1.0 || &gt;=7.2.0

Since Sep 27Pushed 5y agoCompare

[ Source](https://github.com/msyahidin/versionable)[ Packagist](https://packagist.org/packages/develoopin/versionable)[ Docs](http://github.com/develoopin/versionable)[ RSS](/packages/develoopin-versionable/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (4)Versions (28)Used By (0)

Versionable forked from mpociot/Versionable
===========================================

[](#versionable-forked-from-mpociotversionable)

Easy to use Model versioning for Laravel
----------------------------------------

[](#easy-to-use-model-versioning-for-laravel)

[![image](https://camo.githubusercontent.com/b8dd16b521f76680c2086edbbf176a13f9aaad4201cd5e5a5a326bd2dd833464/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646576656c6f6f70696e2f76657273696f6e61626c652e7376673f7374796c653d666c6174)](https://camo.githubusercontent.com/b8dd16b521f76680c2086edbbf176a13f9aaad4201cd5e5a5a326bd2dd833464/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646576656c6f6f70696e2f76657273696f6e61626c652e7376673f7374796c653d666c6174)[![image](https://camo.githubusercontent.com/292ba13070b5fbc41f4151e21735062263d5fdf89b0e46c8b0d3d2322f6c0386/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f646576656c6f6f70696e2f76657273696f6e61626c652e7376673f7374796c653d666c6174)](https://camo.githubusercontent.com/292ba13070b5fbc41f4151e21735062263d5fdf89b0e46c8b0d3d2322f6c0386/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f646576656c6f6f70696e2f76657273696f6e61626c652e7376673f7374796c653d666c6174)[![image](https://camo.githubusercontent.com/4bc13cedfea09ec3cb4de90a6a9a6a30b6728d886983e70915d79dc0999627a3/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646576656c6f6f70696e2f76657273696f6e61626c652e7376673f7374796c653d666c6174)](https://camo.githubusercontent.com/4bc13cedfea09ec3cb4de90a6a9a6a30b6728d886983e70915d79dc0999627a3/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646576656c6f6f70696e2f76657273696f6e61626c652e7376673f7374796c653d666c6174)[![codecov.io](https://camo.githubusercontent.com/a8bbd08332fe203bd1793aaa6530e9bc877adaf6a3b39091e5c87edae9c280fe/68747470733a2f2f636f6465636f762e696f2f6769746875622f646576656c6f6f70696e2f76657273696f6e61626c652f636f7665726167652e7376673f6272616e63683d6d6173746572)](https://codecov.io/github/develoopin/versionable?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/b838d3d5237209853a5e5d1781f116dd30159f9d9c58fc1bb3ae36abf5a08eb5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f646576656c6f6f70696e2f76657273696f6e61626c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/develoopin/versionable/?branch=master)[![Build Status](https://camo.githubusercontent.com/ad17698d874a11089f4116787fe82a41743797745cdab450e920c52d892dded2/68747470733a2f2f7472617669732d63692e6f72672f646576656c6f6f70696e2f76657273696f6e61626c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/develoopin/versionable)

Keep track of all your model changes and revert to previous versions of it.

```
// Restore to the previous change
$content->previousVersion()->revert();

// Get model from a version
$oldModel = Version::find(100)->getModel();
```

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

[](#installation)

In order to add Versionable to your project, just add

```
"develoopin/versionable": "~3.0"

```

to your composer.json. Then run `composer install` or `composer update`.

Or run `composer require develoopin/versionable ` if you prefere that.

Run the migrations to create the "versions" table that will hold all version information.

```
php artisan migrate --path=vendor/develoopin/versionable/src/migrations
```

Usage
-----

[](#usage)

Let the Models you want to set under version control use the `VersionableTrait`.

```
class Content extends Model {

	use develoopin\Versionable\VersionableTrait;

}
```

That's it!

Every time you update your model, a new version containing the previous attributes will be stored in your database.

All timestamps and the optional soft-delete timestamp will be ignored.

### Exclude attributes from versioning

[](#exclude-attributes-from-versioning)

Sometimes you don't want to create a version *every* time an attribute on your model changes. For example your User model might have a `last_login_at` attribute. I'm pretty sure you don't want to create a new version of your User model every time that user logs in.

To exclude specific attributes from versioning, add a new array property to your model named `dontVersionFields`.

```
class User extends Model {

	use develoopin\Versionable\VersionableTrait;

	/**
	 * @var array
	 */
	protected $dontVersionFields = [ 'last_login_at' ];

}
```

### Maximum number of stored versions

[](#maximum-number-of-stored-versions)

You can control the maximum number of stored versions per model. By default, there will be no limit and all versions will be saved. Depending on your application, this could lead to a lot of versions, so you might want to limit the amount of stored versions.

You can do this by setting a `$keepOldVersions` property on your versionable models:

```
class User {

    use VersionableTrait;

    // Keep the last 10 versions.
    protected $keepOldVersions = 10;

}
```

### Retrieving all versions associated to a model

[](#retrieving-all-versions-associated-to-a-model)

To retrieve all stored versions use the `versions` attribute on your model.

This attribute can also be accessed like any other Laravel relation, since it is a `MorphMany` relation.

```
$model->versions;
```

### Getting a diff of two versions

[](#getting-a-diff-of-two-versions)

If you want to know, what exactly has changed between two versions, use the version model's `diff` method.

The diff method takes a version model as an argument. This defines the version to diff against. If no version is provided, it will use the current version.

```
/**
 * Create a diff against the current version
 */
$diff = $page->previousVersion()->diff();

/**
 * Create a diff against a specific version
 */
$diff = $page->currentVersion()->diff( $version );
```

The result will be an associative array containing the attribute name as the key, and the different attribute value.

### Revert to a previous version

[](#revert-to-a-previous-version)

Saving versions is pretty cool, but the real benefit will be the ability to revert to a specific version.

There are multiple ways to do this.

**Revert to the previous version**

You can easily revert to the version prior to the currently active version using:

```
$content->previousVersion()->revert();
```

**Revert to a specific version ID**

You can also revert to a specific version ID of a model using:

```
$revertedModel = Version::find( $version_id )->revert();
```

### Disable versioning

[](#disable-versioning)

In some situations you might want to disable versioning a specific model completely for the current request.

You can do this by using the `disableVersioning` and `enableVersioning` methods on the versionable model.

```
$user = User::find(1);
$user->disableVersioning();

// This will not create a new version entry.
$user->update([
    'some_attribute' => 'changed value'
]);
```

### Use different version table

[](#use-different-version-table)

Some times we want to have models versions in differents tables. By default versions are stored in the table 'versions', defined in develoopin\\Versionable\\Version::$table.

To use a different table to store version for some model we have to change the table name. To do so, create a model that extends develoopin\\Versionable\\Version and set the $table property to another table name.

```
class MyModelVersion extends Version
{
    $table = 'mymodel_versions';
    ...
}
```

In the model that you want it use this specific versions table, use the `VersionableTrait` Trait and add the property `$versionClass` with value the specific version model.

```
class MyModel extends Eloquent
{
    use VersionableTrait ;
    protected $versionClass = MyModelVersion::class ;
    ...
}
```

And do not forget to create a migration for this versions table, exactly as the default versions table.

License
-------

[](#license)

Versionable is free software distributed under the terms of the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 74.8% 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 ~89 days

Recently: every ~198 days

Total

26

Last Release

2010d ago

Major Versions

1.1.0 → 2.0.02015-10-26

2.0.x-dev → 3.0.02018-08-02

PHP version history (3 changes)1.0PHP &gt;=5.3.0

3.0.0PHP &gt;=7.1.0

3.1.2PHP &gt;=7.1.0 || &gt;=7.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6156e34f08d26374af385ba981dac4d04f761ed51001ae15f1d969b47009e6f5?d=identicon)[develoopin](/maintainers/develoopin)

---

Top Contributors

[![mpociot](https://avatars.githubusercontent.com/u/804684?v=4)](https://github.com/mpociot "mpociot (77 commits)")[![Cyrille37](https://avatars.githubusercontent.com/u/368965?v=4)](https://github.com/Cyrille37 "Cyrille37 (5 commits)")[![derhofbauer](https://avatars.githubusercontent.com/u/22151619?v=4)](https://github.com/derhofbauer "derhofbauer (4 commits)")[![kangyasin](https://avatars.githubusercontent.com/u/31263789?v=4)](https://github.com/kangyasin "kangyasin (4 commits)")[![msyahidin](https://avatars.githubusercontent.com/u/24245457?v=4)](https://github.com/msyahidin "msyahidin (3 commits)")[![emilv](https://avatars.githubusercontent.com/u/1684914?v=4)](https://github.com/emilv "emilv (2 commits)")[![oschettler](https://avatars.githubusercontent.com/u/124634?v=4)](https://github.com/oschettler "oschettler (2 commits)")[![williamoliveira](https://avatars.githubusercontent.com/u/6340344?v=4)](https://github.com/williamoliveira "williamoliveira (1 commits)")[![dubcanada](https://avatars.githubusercontent.com/u/120325?v=4)](https://github.com/dubcanada "dubcanada (1 commits)")[![geoffbeaumont](https://avatars.githubusercontent.com/u/3082468?v=4)](https://github.com/geoffbeaumont "geoffbeaumont (1 commits)")[![michaelachrisco](https://avatars.githubusercontent.com/u/398491?v=4)](https://github.com/michaelachrisco "michaelachrisco (1 commits)")[![nhowell](https://avatars.githubusercontent.com/u/200475?v=4)](https://github.com/nhowell "nhowell (1 commits)")[![coffe4u](https://avatars.githubusercontent.com/u/2783407?v=4)](https://github.com/coffe4u "coffe4u (1 commits)")

---

Tags

laravelmodelhistoryrestoreversionardent

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/develoopin-versionable/health.svg)

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

###  Alternatives

[mpociot/versionable

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

7841.1M6](/packages/mpociot-versionable)[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)[panoscape/history

Eloquent model history tracking for Laravel

162130.3k](/packages/panoscape-history)

PHPackages © 2026

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