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

ActiveLibrary

vildanbina/laravel-revisions
============================

Create multiple revisions of any Eloquent model record along with its underlying relationships

00PHP

Since Sep 28Pushed 4y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)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://camo.githubusercontent.com/d1aa1cd6b18c7de57674cfb9ee1bd542428e65e3ac0b2f3b54e0a91ee10acaf9/68747470733a2f2f7472617669732d63692e6f72672f76696c64616e62696e612f6c61726176656c2d7265766973696f6e732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/vildanbina/laravel-revisions)[![StyleCI](https://camo.githubusercontent.com/638bbdbc4467b5d4c320e6658daf7b27327195af925a71df1795f84c9c6ea656/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3137303931353538392f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/170915589)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/23d83e9293ba3a16adb40b4be9dfd0ecbe2200365dbafb0dcd25896e34bca8eb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f76696c64616e62696e612f6c61726176656c2d7265766973696f6e732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/vildanbina/laravel-revisions/?branch=master)

- [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 can 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 vildanbina/laravel-revisions

```

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

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

```

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

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

```

Publish the config file with:

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

```

Publish the migration file with:

```
php artisan vendor:publish --provider="vildanbina\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 `vildanbina\Revisions\Traits\HasRevisions` trait and the `vildanbina\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:

```
