PHPackages                             calamandrei-lorenzo/laravel-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. calamandrei-lorenzo/laravel-versionable

ActiveLibrary

calamandrei-lorenzo/laravel-versionable
=======================================

Make Laravel model versionable.

2.0.0(5y ago)00MITPHPPHP ^7.4

Since May 31Pushed 5y agoCompare

[ Source](https://github.com/CalamandreiLorenzo/laravel-versionable)[ Packagist](https://packagist.org/packages/calamandrei-lorenzo/laravel-versionable)[ Patreon](https://www.patreon.com/overtrue)[ RSS](/packages/calamandrei-lorenzo-laravel-versionable/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (5)Versions (11)Used By (0)

 laravel-versionable
=====================

[](#-laravel-versionable-)

Forked from [overtrue/laravel-versionable](https://github.com/overtrue/laravel-versionable)

 ⏱️ Make Laravel model versionable.

[![Build Status](https://github.com/CalamandreiLorenzo/laravel-versionable/workflows/CI/badge.svg)](https://github.com/CalamandreiLorenzo/laravel-versionable/actions)[![Latest Stable Version](https://camo.githubusercontent.com/7a6c2aa95ab908ae5d109de81f4cf6fea1693d4177830cc7163b132f114af0b1/68747470733a2f2f706f7365722e707567782e6f72672f63616c616d616e647265692d6c6f72656e7a6f2f6c61726176656c2d76657273696f6e61626c652f762f737461626c652e737667)](https://packagist.org/packages/calamandrei-lorenzo/laravel-versionable)[![Latest Unstable Version](https://camo.githubusercontent.com/d34129528484a76d1a674840b2c6e5d421c98d76571c7194f15c0d67c9e7e980/68747470733a2f2f706f7365722e707567782e6f72672f63616c616d616e647265692d6c6f72656e7a6f2f6c61726176656c2d76657273696f6e61626c652f762f756e737461626c652e737667)](https://packagist.org/packages/calamandrei-lorenzo/laravel-versionable)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/fb40bf92c4e633cd6691890a59bc1d59a270f3f5a9e8f6d3b540a68c822a146d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f43616c616d616e647265694c6f72656e7a6f2f6c61726176656c2d76657273696f6e61626c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/CalamandreiLorenzo/laravel-versionable/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/e7c85e4cb1cc48d524487ce8797a103f264b13a741d88776428668f42082bdb2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f43616c616d616e647265694c6f72656e7a6f2f6c61726176656c2d76657273696f6e61626c652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/CalamandreiLorenzo/laravel-versionable/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/f56525828fd065e4b2e1d26a2dba858813af81454a6634f72bde2d47e4d1bbb7/68747470733a2f2f706f7365722e707567782e6f72672f63616c616d616e647265692d6c6f72656e7a6f2f6c61726176656c2d76657273696f6e61626c652f646f776e6c6f616473)](https://packagist.org/packages/calamandrei-lorenzo/laravel-versionable)[![License](https://camo.githubusercontent.com/fa58a574f55e20c3febec97ed8f1f07a32ed564a9489d307066f57f7060f7c9f/68747470733a2f2f706f7365722e707567782e6f72672f63616c616d616e647265692d6c6f72656e7a6f2f6c61726176656c2d76657273696f6e61626c652f6c6963656e7365)](https://packagist.org/packages/calamandrei-lorenzo/laravel-versionable)

It's a minimalist way to make your model support version history, and it's very simple to roll back to the specified version.

Requirement
-----------

[](#requirement)

1. PHP &gt;= 7.4
2. laravel/framework &gt;= 5.8|6.0|7.0

Features
--------

[](#features)

- Keep the specified number of versions.
- Whitelist and blacklist for versionable attributes.
- Easily roll back to the specified version.
- Record only changed attributes.
- Easy to customize.

Installing
----------

[](#installing)

```
$ composer require overtrue/laravel-versionable -vvv
```

Optional, you can publish the config file:

```
$ php artisan vendor:publish --provider="CalamandreiLorenzo\\LaravelVersionable\\ServiceProvider" --tag=config
```

And if you want to custom the migration of the versions table, you can publish the migration file to your database path:

```
$ php artisan vendor:publish --provider="CalamandreiLorenzo\\LaravelVersionable\\ServiceProvider" --tag=migrations
```

Then run this command to create a database migration:

```
$ php artisan migrate
```

Usage
-----

[](#usage)

Add `CalamandreiLorenzo\LaravelVersionable\Versionable` trait to the model and set versionable attributes:

```
use CalamandreiLorenzo\LaravelVersionable\Versionable;

class Post extends Model
{
    use Versionable;

    /**
     * Versionable attributes
     *
     * @var array
     */
    protected $versionable = ['title', 'content'];

}
```

Versions will be created on vensionable model saved.

```
$post = Post::create(['title' => 'version1', 'content' => 'version1 content']);
$post->update(['title' => 'version2']);
```

### Get versions

[](#get-versions)

Get all versions

```
$post->versions;
```

Get last version

```
$post->lastVersion;
```

### Reversion

[](#reversion)

Reversion a model instance to the specified version:

```
$post->getVersion('uuid-...')->revert();
$post->getVersionByVersionNumber('uuid-...')->revert();

// or

$post->revertToVersion('uuid-...');
$post->revertToVersionNumber(3);
```

### Remove versions

[](#remove-versions)

```
// soft delete
$post->removeVersion($versionId = 1);
$post->removeVersions($versionIds = [1, 2, 3]);
$post->removeAllVersions();

// force delete
$post->forceRemoveVersion($versionId = 1);
$post->forceRemoveVersions($versionIds = [1, 2, 3]);
$post->forceRemoveAllVersions();
```

### Restore deleted version by id

[](#restore-deleted-version-by-id)

```
$post->restoreThrashedVersion($id);
```

### Temporarily disable versioning

[](#temporarily-disable-versioning)

```
// create
Post::withoutVersion(function () use (&$post) {
    Post::create(['title' => 'version1', 'content' => 'version1 content']);
});

// update
Post::withoutVersion(function () use ($post) {
    $post->update(['title' => 'updated']);
});
```

### Custom Version Store strategy

[](#custom-version-store-strategy)

You can set the following different version policies through property `protected $versionStrategy`:

- `CalamandreiLorenzo\LaravelVersionable::DIFF` - Version content will only contain changed attributes (Default Strategy).
- `CalamandreiLorenzo\LaravelVersionable::SNAPSHOT` - Version content will contain all versionable attributes values.

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

[](#contributing)

You can contribute in one of three ways:

1. File bug reports using the [issue tracker](https://github.com/overtrue/laravel-versionable/issues).
2. Answer questions or fix bugs on the [issue tracker](https://github.com/overtrue/laravel-versionable/issues).
3. Contribute new features or update the wiki.

*The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.*

License
-------

[](#license)

MIT

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 73.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 ~50 days

Recently: every ~31 days

Total

9

Last Release

2134d ago

Major Versions

1.1.5 → 2.0.02020-07-09

PHP version history (2 changes)1.0.0PHP ^7.1.3

2.0.0PHP ^7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/802e0a6db2648f02dda2eb3541beb12333a85956fcdd0a7c9220bbc4342419ee?d=identicon)[Lorenzo Calamandrei](/maintainers/Lorenzo%20Calamandrei)

---

Top Contributors

[![overtrue](https://avatars.githubusercontent.com/u/1472352?v=4)](https://github.com/overtrue "overtrue (34 commits)")[![CalamandreiLorenzo](https://avatars.githubusercontent.com/u/22129349?v=4)](https://github.com/CalamandreiLorenzo "CalamandreiLorenzo (4 commits)")[![YDoomA](https://avatars.githubusercontent.com/u/42892323?v=4)](https://github.com/YDoomA "YDoomA (3 commits)")[![thewebartisan7](https://avatars.githubusercontent.com/u/57477934?v=4)](https://github.com/thewebartisan7 "thewebartisan7 (2 commits)")[![uptutu](https://avatars.githubusercontent.com/u/23716080?v=4)](https://github.com/uptutu "uptutu (2 commits)")[![zolotov88](https://avatars.githubusercontent.com/u/11463586?v=4)](https://github.com/zolotov88 "zolotov88 (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/calamandrei-lorenzo-laravel-versionable/health.svg)

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

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[namu/wirechat

A Laravel Livewire messaging app for teams with private chats and group conversations.

54324.5k](/packages/namu-wirechat)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135192.6k5](/packages/statamic-rad-pack-runway)

PHPackages © 2026

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