PHPackages                             wearesweet/laravel-revisonable - 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. wearesweet/laravel-revisonable

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

wearesweet/laravel-revisonable
==============================

Apply the trait HasRevisions to any model to be able to: View a history of changes, revert to previous versions of the model and allow for easy moderation of changes before persisting to the database.

20[4 issues](https://github.com/WeAreSweet/laravel-revisionable/issues)PHP

Since Jul 29Pushed 5y ago2 watchersCompare

[ Source](https://github.com/WeAreSweet/laravel-revisionable)[ Packagist](https://packagist.org/packages/wearesweet/laravel-revisonable)[ RSS](/packages/wearesweet-laravel-revisonable/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Revertible model revisions for Laravel
======================================

[](#revertible-model-revisions-for-laravel)

[![Latest Stable Version](https://camo.githubusercontent.com/92d089aa072a8c5c5ff53f4db5492d66af0f300bd6ee25fd5a9ef27b9b39fccc/68747470733a2f2f706f7365722e707567782e6f72672f776561726573776565742f6c61726176656c2d7265766973696f6e61626c652f762f737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/wearesweet/laravel-revisionable)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![GitHub Tests Action Status](https://camo.githubusercontent.com/93b5ab134721c570aa50022a09da105161f738b3c2c2c5e1300f6537021be7d6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f776561726573776565742f6c61726176656c2d7265766973696f6e61626c652f72756e2d74657374733f6c6162656c3d7465737473)](https://camo.githubusercontent.com/93b5ab134721c570aa50022a09da105161f738b3c2c2c5e1300f6537021be7d6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f776561726573776565742f6c61726176656c2d7265766973696f6e61626c652f72756e2d74657374733f6c6162656c3d7465737473)[![Quality Score](https://camo.githubusercontent.com/1498cabd3c1e7dcdc86eb63281b21b7b301c3c2c64840dc0dd08203703085f49/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f776561726573776565742f6c61726176656c2d7265766973696f6e61626c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/wearesweet/laravel-revisionable)[![Total Downloads](https://camo.githubusercontent.com/fdeb33647fe57b9d4d40683dc6b56bbf4ec790a24c4980727b7f1936d86d52f8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f776561726573776565742f6c61726176656c2d7265766973696f6e61626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/wearesweet/laravel-revisionable)

Apply the trait HasRevisions to any model to be able to: View a history of changes, revert to previous versions of the model and allow for easy moderation of changes before persisting to the database.

About We Are Sweet
------------------

[](#about-we-are-sweet)

We Are Sweet is a small but mighty wb agency providing design development and consultancy services to a wide range of clients.

[Check us out](https://www.wearesweet.co.uk/)

Installation and usage
----------------------

[](#installation-and-usage)

This package requires PHP 7.6 and Laravel 6 or higher.

Run

```
$ composer require wearesweet/laravel-revisionable
```

### HasRevisions Trait

[](#hasrevisions-trait)

Add the HasRevisions trait to your model(s).

```
class User {
    use WeAreSweet\LaravelRevisionable\Traits\HasRevisions;
}
```

### Listen for certain attributes

[](#listen-for-certain-attributes)

Override revisionableAttributes so that it returns an array of attributes you want to allow revisions for.

If using revisionableAttributes in conjunction with persistRevisions, attributes in your array will be stored as a revision which can later be persisted (approved) and all other attributes not in the array will be persisted imminently.

```
class User {
    use WeAreSweet\LaravelRevisionable\Traits\HasRevisions;

    public function revisionableAttributes()
    {
        return 'name';
    }
}
```

### Prevent persisting model data to the database unless approved

[](#prevent-persisting-model-data-to-the-database-unless-approved)

You can tell your models not to save directly to the model and instead save the data in revisions which can be applied to the model later.

This is useful for storing draft states of your models or for moderating and approving changes.

To do this, add the method persistRevisions to your class and have it return false.

```
class User {
    use WeAreSweet\LaravelRevisionable\Traits\HasRevisions;

    public function persistRevisions()
    {
        return false;
    }
}
```

### View all models revision history

[](#view-all-models-revision-history)

```
App\User::first()->revisions;
```

### View pending model revisions

[](#view-pending-model-revisions)

```
App\User::first()->revisions()->pending()->get();
```

### Approve a revision

[](#approve-a-revision)

```
App\User::first()->revisions->first()->approve();
```

### View merged pending revisions data

[](#view-merged-pending-revisions-data)

```
App\User::first()->pendingRevisions();
```

#### Example input/output

[](#example-inputoutput)

##### Input:

[](#input)

```
{
  "user":{
    "revisions": [
      {
        "date": "2020",
        "data": {"name": "Ben"}
      },
      {
        "date": "2010",
        "data": {"name": "Neb", "age":  23}
      }
    ]
  }
}
```

##### Output:

[](#output)

```
{
  "name": "Ben",
  "age": 23
}
```

### Approve all model revisions

[](#approve-all-model-revisions)

```
App\User::first()->approveAllRevisions();
```

Testing
-------

[](#testing)

Run the tests with:

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Ben Watson](https://github.com/blwsh)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

12

—

LowBetter than 0% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/64540888?v=4)[We Are Sweet](/maintainers/wearesweet)[@WeAreSweet](https://github.com/WeAreSweet)

---

Top Contributors

[![blwsh](https://avatars.githubusercontent.com/u/32358483?v=4)](https://github.com/blwsh "blwsh (5 commits)")

### Embed Badge

![Health badge](/badges/wearesweet-laravel-revisonable/health.svg)

```
[![Health](https://phpackages.com/badges/wearesweet-laravel-revisonable/health.svg)](https://phpackages.com/packages/wearesweet-laravel-revisonable)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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