PHPackages                             mpociot/reanimate - 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. mpociot/reanimate

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

mpociot/reanimate
=================

Undo Laravel soft deletes

1.0.0(11y ago)1221.2k7[1 issues](https://github.com/mpociot/reanimate/issues)MITPHPPHP &gt;=5.3.0

Since Mar 18Pushed 11y ago6 watchersCompare

[ Source](https://github.com/mpociot/reanimate)[ Packagist](https://packagist.org/packages/mpociot/reanimate)[ Docs](http://github.com/mpociot/reanimate)[ RSS](/packages/mpociot-reanimate/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependencies (7)Versions (3)Used By (0)

[![Reanimate](https://camo.githubusercontent.com/037e3901088399f65efdaaecb30e14f4c9082fccb73be769cc0fcc4f74962f9c/687474703a2f2f7777772e746974616e69756d636f6e74726f6c732e636f6d2f6769742f7265616e696d6174652e706e67)](https://camo.githubusercontent.com/037e3901088399f65efdaaecb30e14f4c9082fccb73be769cc0fcc4f74962f9c/687474703a2f2f7777772e746974616e69756d636f6e74726f6c732e636f6d2f6769742f7265616e696d6174652e706e67)

[ ![](https://camo.githubusercontent.com/f3e3f59826d2baa0a7372b81fa0796e0b2109c811ea7779be5f1a56c44e2ea96/687474703a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f6d706f63696f742f7265616e696d6174652e7376673f7374796c653d666c6174)](https://packagist.org/packages/mpociot/reanimate)[ ![](https://camo.githubusercontent.com/10b00e93f7b63ebfc90aadb52e5f47352e6079ea7a0db6dc20a84d62d9164603/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d706f63696f742f7265616e696d6174652e7376673f7374796c653d666c6174)](https://packagist.org/packages/mpociot/reanimate)[ ![](https://camo.githubusercontent.com/c86aa4acb0b65f1d93139180febfc7b404133ef305a6e4bef41ffc161f7e0095/68747470733a2f2f7472617669732d63692e6f72672f6d706f63696f742f7265616e696d6174652e7376673f6272616e63683d646576656c6f70)](https://travis-ci.org/mpociot/reanimate)Restoring models in laravel is easy. Simply call `restore` on the soft-deleted model and you're good to go. But what if you want to implement a simple `undo` mechanism in your application?

You need to take care of restoring the model, redirecting back, showing a success/error message...

Wouldn't it be nice if this process could be simplified?

Reanimate is a laravel package that allows you to do just that. It simplifies undoing of soft-deletes for your application.

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

[](#installation)

Reanimate can be installed via [composer](http://getcomposer.org/doc/00-intro.md), the details are on [packagist, here.](https://packagist.org/packages/mpociot/reanimate)

To download and use this package, add the following to the `require` section of your projects composer.json file:

```
"mpociot/reanimate": "1.*",
```

Run composer update to download the package

```
php composer.phar update

```

That's it. Take a look at the implementation guide, to get started.

Docs
----

[](#docs)

- [What Reanimate does](#about)
- [Implementation](#intro)
- [Contributing](#contributing)

What Reanimate does
-------------------

[](#what-reanimate-does)

A simplified `delete`method on your controller might look like this:

```
public function delete( User $user )
{
	$user->delete();
	return Redirect::route( "userIndex" )->with( "message", "userDeleted" );
}
```

So how would you undo that delete call? You need to create a route, pass that object id, resolve the object, restore it if it exists and finally redirect back.

With Reanimate, this becomes:

```
public function delete( User $user )
{
	$user->delete();
	return Redirect::route( "userIndex" )->with( "message", "userDeleted" )->with( $this->undoFlash( $user ) );
}
```

`undoFlash` passes an array to your session with the following data:

```
"undo" => [
	"route"  => "userUndo",
	"params" => [ "DELETED_MODEL_ID" ],
	"lang"   => "user.undo.message"
]
```

So if your session has an `undo` array, you know that you should present your users a possibility to undo the deletion.

Just make sure that the undo route, points to the `undoDelete` method, available through the Reanimate Trait.

This method will then restore the model with the given ID and will redirect the user to a given index route.

Implementation &amp; configuration
----------------------------------

[](#implementation--configuration)

Every controller in your application, that currently takes care of deleting a model and now should benefit from Reanimate, needs to use the `ReanimateModels` Traits.

For example

```
namespace App\Http\Controllers;

class UserController extends Controller {
    use \Mpociot\Reanimate\ReanimateModels;
}
```

### Deletes

[](#deletes)

When you redirect your users after a successful `delete` call, simply append the `->with( $this->undoFlash( $deletedModel ) );` data to your redirect.

undoFlash will automatically do two things for you:

**Auto generate an undo route:**

When no custom undo route is specified, Reanimate generates a named route by using the model name + "Undo".

Example model names and undo routes:

> User -&gt; userUndo
>
> Category -&gt; categoryUndo
>
> FileEntry -&gt; fileEntryUndo

**Auto generate an undo language key:**

By default, a `lang` key can be used within your views, for the undo action. This key is a lowercase representation of your model name + `.undo.message`

Example model names and lang keys:

> User -&gt; user.undo.message
>
> Category -&gt; category.undo.message
>
> FileEntry -&gt; fileentry.undo.message

### Restores

[](#restores)

The easiest way to restore your models, is to add a named route to your `routes.php` that matches the generated undo route name.

This route needs to point to the `undoDelete` method of your controller.

This method takes care of restoring the model with the given primary key and returns a redirect to an auto generated index route.

**Auto generated model name:**

Since this method only receives the ID of your model, but not the model itself, Reanimate tries to guess the correct model name for you.

It's done by using the singular version of your Controller's name.

Example controller names and the matching model names:

> UserController -&gt; User
>
> CategoriesController -&gt; Category
>
> FileEntryController -&gt; FileEntry

**Auto generated index route:**

When no custom index route is specified, Reanimate generates a named route by using the model name + "Index".

Example model names and undo routes:

> User -&gt; userIndex
>
> Category -&gt; categoryIndex
>
> FileEntry -&gt; fileEntryIndex

The redirect will also contain a flash data named `message` that contains either:

`modelname.undo.restored` on success or `modelname.undo.invalid` when no model with the given ID could be found.

### Customization

[](#customization)

Don't like the auto generated routes? Don't like the auto generated model names? No problem!

Simply override them in your controller class like this:

```
namespace App\Http\Controllers;

class UserController extends Controller {
    use \Mpociot\Reanimate\ReanimateModels;

    protected $undoDeleteModel = 'This\Is\My\Custom\Model';

    protected $indexRoute = 'home';

    protected $undoRoute = 'ohNooooo';

}
```

You can also write your own `undoDelete` method, if you want some more control:

```
namespace App\Http\Controllers;

class UserController extends Controller {
    use \Mpociot\Reanimate\ReanimateModels;

    public function myCustomUndoMethod( $primaryKey )
    {
    	return $this->restoreModel( $primaryKey , new User(), "myCustomIndexRoute" );
    }

}
```

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

[](#contributing)

Contributions are encouraged and welcome; to keep things organised, all bugs and requests should be opened in the github issues tab for the main project, at [mpociot/reanimate/issues](https://github.com/mpociot/reanimate/issues)

All pull requests should be made to the `develop` branch, so they can be tested before being merged into the master branch.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity59

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

4078d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b46cb765edab3c6a765bd466bb2a530e0e95cbd74cf7dfc250c59a2b029b73ca?d=identicon)[mpociot](/maintainers/mpociot)

---

Top Contributors

[![mpociot](https://avatars.githubusercontent.com/u/804684?v=4)](https://github.com/mpociot "mpociot (6 commits)")

---

Tags

laravelmodelrestoresoftdeleteundo

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mpociot-reanimate/health.svg)

```
[![Health](https://phpackages.com/badges/mpociot-reanimate/health.svg)](https://phpackages.com/packages/mpociot-reanimate)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[yajra/laravel-datatables-oracle

jQuery DataTables API for Laravel

4.9k33.8M339](/packages/yajra-laravel-datatables-oracle)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[watson/active

Laravel helper for recognising the current route, controller and action

3253.6M14](/packages/watson-active)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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