PHPackages                             laraversion/laraversion - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. laraversion/laraversion

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

laraversion/laraversion
=======================

A Laravel package for versioning models with a simple and scalable approach.

v1.0.4(2y ago)1822MITPHPPHP ^8.1

Since Mar 2Pushed 2y ago1 watchersCompare

[ Source](https://github.com/latomate07/laraversion)[ Packagist](https://packagist.org/packages/laraversion/laraversion)[ Docs](https://github.com/laraversion/laraversion)[ RSS](/packages/laraversion-laraversion/feed)WikiDiscussions master Synced 1mo ago

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

 [![](art/logo.png)](art/logo.png)

About Laraversion
=================

[](#about-laraversion)

Laraversion is a Laravel package that simplifies version management for your Eloquent models. It allows you to easily track and restore previous versions of your data using a Git-inspired versioning system.

Table of Contents
-----------------

[](#table-of-contents)

1. [Features](#features)
2. [Requirements](#requirements)
3. [Installation](#installation)
4. [Usage](#usage)
    - [Using the Trait](#using-the-trait)
    - [Available Methods](#available-methods)
    - [Listening to Events](#listening-to-events)
    - [Facade Usage](#facade-usage)
    - [Examples](#examples)
5. [Installing the Graphical User Interface (Optional)](#installing-gui)
6. [Commands](#commands)
    - [List all versions](#list-all-versions)
    - [Restore a specific version](#restore-specific-version)
    - [Compare two versions](#compare-two-versions)
7. [Configuration](#configuration)
    - [Excluding Attributes from Versioning](#excluding-attributes)
8. [Use Cases](#use-cases)
9. [Contribution](#contribution)
10. [License](#license)

Features
--------------------------------------------

[](#features)

- Automatic version tracking for Eloquent models.
- Easy restoration of previous versions.
- Support for Laravel model events (created, updated, deleted, restored, forceDeleted).
- Storage of version data in a dedicated table with unique UUIDs.
- Easy configuration of the maximum number of versions to retain.
- Events for version creation, pruning, and restoration.
- Ability to specify which model attributes to exclude from versioning.

Requirements
----------------------------------------------------

[](#requirements)

- PHP ^8.1
- Laravel ^9.0

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

[](#installation)

1. Install the package via Composer:

```
composer require laraversion/laraversion

```

2. Publish the package configuration &amp; migration file:

```
php artisan vendor:publish --provider="Laraversion\Laraversion\LaraversionServiceProvider"
```

3. Run the migrations:

```
php artisan migrate

```

Usage
--------------------------------------

[](#usage)

### Using the Trait

[](#using-the-trait)

To use Laraversion in your models, add the `Laraversion\Laraversion\Traits\Versionable` trait:

```
use Laraversion\Laraversion\Traits\Versionable;

class YourModel extends Model
{
    use Versionable;
}
```

### Available Methods

[](#available-methods)

When using the Versionable trait in your model, the following methods are available:

1. `versionHistory()`: Get the version history for a given model.
2. `recordVersion(VersionEventType $eventType)`: Record a new version for the model.
3. `revertToVersion(string $commitId)`: Revert the model to a specific version.
4. `resetToLastVersion()`: Revert the model to its last modified version.
5. `resetToVersionAtDate(Carbon $date)`: Revert the model to the version at a specific date.
6. `getVersionDiff(string $commitId1, string $commitId2)`: Get the differences between two versions of a model.

### Listening to Events

[](#listening-to-events)

Laraversion fires events when specific actions occur, allowing you to perform additional processing or custom actions. To listen to these events, you can create event listeners and register them in your application.

Here are the events fired by Laraversion:

- `VersionCreatedEvent`: Triggered when a new version is created for a model.
- `VersionPrunedEvent`: Triggered when an old version is deleted to maintain the maximum number of versions.
- `VersionRestoredEvent`: Triggered when a soft-deleted model is restored.

To create an event listener, you can create a file like the following:

```
