PHPackages                             proai/eloquent-versioning - 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. proai/eloquent-versioning

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

proai/eloquent-versioning
=========================

An extension for the Eloquent ORM to support versioning.

1.0.7(7y ago)7125.9k27[8 issues](https://github.com/ProAI/eloquent-versioning/issues)[5 PRs](https://github.com/ProAI/eloquent-versioning/pulls)MITPHPPHP &gt;=7.1

Since Jun 21Pushed 6y ago5 watchersCompare

[ Source](https://github.com/ProAI/eloquent-versioning)[ Packagist](https://packagist.org/packages/proai/eloquent-versioning)[ Docs](http://github.com/ProAI/eloquent-versioning)[ RSS](/packages/proai-eloquent-versioning/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (5)Versions (10)Used By (0)

Eloquent Versioning
===================

[](#eloquent-versioning)

[![Latest Stable Version](https://camo.githubusercontent.com/b02671e5eed671e44e05592c229bd5e10204759b8c08cea1377bbdc3a605d1c5/68747470733a2f2f706f7365722e707567782e6f72672f70726f61692f656c6f7175656e742d76657273696f6e696e672f762f737461626c65)](https://packagist.org/packages/proai/eloquent-versioning) [![Total Downloads](https://camo.githubusercontent.com/df6c28a87ece98b8223a0240f8cdb7e18166fc3f5b4be9849ae7217e77c0da51/68747470733a2f2f706f7365722e707567782e6f72672f70726f61692f656c6f7175656e742d76657273696f6e696e672f646f776e6c6f616473)](https://packagist.org/packages/proai/eloquent-versioning) [![Latest Unstable Version](https://camo.githubusercontent.com/06bd7fd8b347ca5b93a4d2f7665c692f90910adabecb75883bcea8551f10ab7d/68747470733a2f2f706f7365722e707567782e6f72672f70726f61692f656c6f7175656e742d76657273696f6e696e672f762f756e737461626c65)](https://packagist.org/packages/proai/eloquent-versioning) [![License](https://camo.githubusercontent.com/525c9c85d87d1fa99d4d48b15bb454e06b9c916b15d1a00dfc01a806a64c4ada/68747470733a2f2f706f7365722e707567782e6f72672f70726f61692f656c6f7175656e742d76657273696f6e696e672f6c6963656e7365)](https://packagist.org/packages/proai/eloquent-versioning)

This is an extension for the Eloquent ORM to support versioning. You can specify attributes as versioned. If an attribute is specified as versioned the value will be saved in a separate version table on each update. It is possible to use timestamps and soft deletes with this feature.

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

[](#installation)

Eloquent Versioning is distributed as a composer package. So you first have to add the package to your `composer.json` file:

```
"proai/eloquent-versioning": "~1.0"

```

Then you have to run `composer update` to install the package.

Example
-------

[](#example)

We assume that we want a simple user model. While the username should be fixed, the email and city should be versionable. Also timestamps and soft deletes should be versioned. The migrations would look like the following:

```
...

Schema::create('users', function(Blueprint $table) {
    $table->increments('id');
    $table->integer('latest_version');
    $table->string('username');
    $table->timestamp('created_at');
});

Schema::create('users_version', function(Blueprint $table) {
    $table->integer('ref_id')->primary();
    $table->integer('version')->primary();
    $table->string('email');
    $table->string('city');
    $table->timestamp('updated_at');
    $table->timestamp('deleted_at');
});

...
```

The referring Eloquent model should include the code below:

```
