PHPackages                             nexuspoint/laravel-versioned - 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. nexuspoint/laravel-versioned

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

nexuspoint/laravel-versioned
============================

Versioning for Eloquent Models

1.0.2(10y ago)133.5k4[4 issues](https://github.com/nexuspointltd/laravel-versioned/issues)MITPHPPHP &gt;=5.5.9

Since Sep 15Pushed 10y ago1 watchersCompare

[ Source](https://github.com/nexuspointltd/laravel-versioned)[ Packagist](https://packagist.org/packages/nexuspoint/laravel-versioned)[ RSS](/packages/nexuspoint-laravel-versioned/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (2)Versions (7)Used By (0)

Laravel Versioned
=================

[](#laravel-versioned)

A Laravel 5 package to handle versioning on any of your Eloquent models.

Example Usage
-------------

[](#example-usage)

```
$post = new App\Post();
$post->title = 'Some title';
$post->body = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.';
$post->save();

echo $post->getCurrentVersion(); // 1

```

The post is saved. There are no previous versions.

Now we can update the post.

```
$post->body = 'New body text';
$post->save();

echo $post->getCurrentVersion(); // 2

```

We've automatically versioned it.

```
$post->body = 'Even newer body text';
$post->save();

echo $post->getCurrentVersion(); // 3

```

And again.

```
$post->restoreVersion(1); // true

echo $post->getCurrentVersion(); // 4

$post->toArray();

[
     "title" => "Some title",
     "body" => "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
     "updated_at" => "2015-09-15 19:43:45",
     "created_at" => "2015-09-15 19:41:17",
     "id" => 1,
]

```

Now we've restored the data as it was at version 1, but as a new version.

```
$post->rollback();

echo $post->getCurrentVersion(); // 3

$post->toArray();

[
     "title" => "Some title",
     "body" => "Even newer body text",
     "updated_at" => "2015-09-15 19:43:45",
     "created_at" => "2015-09-15 19:41:17",
     "id" => 1,
]

```

Rollback is effectively an 'undo' on the model. It also removes the history so we're back at version 3.

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

[](#installation)

Install with Composer:

```
composer require nexuspoint/versioned

```

Then create the following migration:

```
