PHPackages                             poluektov-software/laravel-relation-restore - 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. poluektov-software/laravel-relation-restore

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

poluektov-software/laravel-relation-restore
===========================================

Package to remove and restore related models

1.0.0(6y ago)04MITPHPPHP &gt;=7.1.0

Since Nov 20Pushed 6y ago1 watchersCompare

[ Source](https://github.com/poluektov-software/laravel-relation-restore)[ Packagist](https://packagist.org/packages/poluektov-software/laravel-relation-restore)[ RSS](/packages/poluektov-software-laravel-relation-restore/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (2)Used By (0)

Laravel Relation Restore
========================

[](#laravel-relation-restore)

[Документация на русском](README-ru.md)

Description
-----------

[](#description)

Laravel Relation Restore - Laravel package for deleting and restoring related models. This package uses the soft delete method. The package can be useful where you want to delete and restore models with complex chains of related models.

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

[](#installation)

Add the following to your require part within the composer.json:

```
"poluektov-software/laravel-relation-restore": "*"
```

```
$ php composer update
```

or

```
$ php composer require poluektov-software/laravel-relation-restore

```

Usage
-----

[](#usage)

In the database, you must create an additional field for each model. In migrations, for example, you can add the following line:

```
//...
$table->integer( 'remove_code' )->nullable();
//...
```

You need to use the **Relationship Restore** trait in your models:

```
//...
use Poluektov\RelationRestore\RelationRestore;

/**
 * Class Model
 *
 * @package App\Models
 */
class Model
{
    use RelationRestore;
//...
```

Each model must have a unique code:

```
//...
    protected $autoRemoveCode = 100;
//...
```

You must delete and restore related models through methods **autoRemove** and **autoRestore** respectively:

```
    /**
     * Model events handlers.
     *
     */
    public static function boot()
    {
        parent::boot();

        static::deleting( function ( Model $model ) {
            $model->relatedModels->each( function ( $relatedModel ) {
                $relatedModel->autoRemove( $model->getAutoRemove() );
            } );
        } );

        static::restoring( function ( Model $model ) {
            $model->relatedModels()->onlyAutoRemoved( $model->getAutoRemove() )->each( function ( $relatedModel ) {
                $relatedModel->autoRestore();
            } );
        } );
    }
```

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2366d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b3c29a49a1e193412e1483fca204798625a8ed0b718091fac228501e6b7d16d7?d=identicon)[poluektov-software](/maintainers/poluektov-software)

---

Top Contributors

[![poluektov-software](https://avatars.githubusercontent.com/u/10282017?v=4)](https://github.com/poluektov-software "poluektov-software (2 commits)")

---

Tags

laravelmodelrestorerelation

### Embed Badge

![Health badge](/badges/poluektov-software-laravel-relation-restore/health.svg)

```
[![Health](https://phpackages.com/badges/poluektov-software-laravel-relation-restore/health.svg)](https://phpackages.com/packages/poluektov-software-laravel-relation-restore)
```

###  Alternatives

[mpociot/versionable

Allows to create Laravel 4 / 5 / 6 / 7 / 8 / 9 / 10 / 11 Model versioning and restoring

7841.1M6](/packages/mpociot-versionable)[shiftonelabs/laravel-cascade-deletes

Adds application level cascading deletes to Eloquent Models.

163632.1k2](/packages/shiftonelabs-laravel-cascade-deletes)[dcat/laravel-wherehasin

Laravel ORM whereHasIn

247149.8k4](/packages/dcat-laravel-wherehasin)[highsolutions/eloquent-sequence

A Laravel package for easy creation and management sequence support for Eloquent models with elastic configuration.

121130.3k](/packages/highsolutions-eloquent-sequence)[phaza/single-table-inheritance

Single Table Inheritance Trait

1515.8k](/packages/phaza-single-table-inheritance)

PHPackages © 2026

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