PHPackages                             minasm/laravel-revisions - 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. minasm/laravel-revisions

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

minasm/laravel-revisions
========================

An update for from neurony. Create multiple revisions of any Eloquent model record along with its underlying relationships

v1.0.2(1y ago)0103MITPHPPHP ^8.2

Since Oct 9Pushed 1y agoCompare

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

READMEChangelog (2)Dependencies (5)Versions (4)Used By (0)

### Create revisions for any Eloquent model along with its relationships

[](#create-revisions-for-any-eloquent-model-along-with-its-relationships)

[![Build Status](https://github.com/minasm/laravel-revisions/workflows/tests/badge.svg)](https://github.com/minasm/laravel-revisions/actions/)

- [Overview](#overview)
- [Installation](#installation)
- [Setup](#setup)
- [Usage](#usage)
- [Customisations](#customisations)
- [Events](#events)

### Overview

[](#overview)

This package allows you to create revisions for any Eloquent model record along with its underlying relationships.

- When a revision is created, it gets stored inside the `revisions` database table.
- Revisions are created automatically on model update, using the `updated` Eloquent event
- Revisions can also be created manually by using the `saveAsRevision()`
- When a record is force deleted, all its revisions will also be removed automatically, using the `deleted` Eloquent event

As already mentioned, this package is capable of revisioning entire relationships alongside the model record.

**The cool part is that it's also capable of re-creating the relationships records from ground up, if they were force deleted along the way, during the lifetime of that model record.**

Relationship types that can be revisioned: `hasOne`, `morphOne`, `hasMany`, `morphMany`, `belongsToMany`, `morphToMany`

### Installation

[](#installation)

Install the package via Composer (for **Laravel 6.0 and above**):

```
composer require minasm/laravel-revisions

```

Install the package via Composer (for **Laravel 5.8**):

```
composer require minasm/laravel-revisions:3.1.0

```

Install the package via Composer (for **Laravel 5.7 and below**):

```
composer require minasm/laravel-revisions:2.0.0

```

Publish the config file with:

```
php artisan vendor:publish --provider="Neurony\Revisions\ServiceProvider" --tag="config"

```

Publish the migration file with:

```
php artisan vendor:publish --provider="Neurony\Revisions\ServiceProvider" --tag="migrations"

```

After the migration has been published you can create the `revisions` table by running:

```
php artisan migrate

```

### Setup

[](#setup)

##### Step 1

[](#step-1)

Your Eloquent models should use the `Neurony\Revisions\Traits\HasRevisions` trait and the `Neurony\Revisions\Options\RevisionOptions` class.

The trait contains an abstract method `getRevisionOptions()` that you must implement yourself.

Here's an example of how to implement the trait:

```
