PHPackages                             muffin/trash - 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. muffin/trash

ActiveCakephp-plugin[Database &amp; ORM](/categories/database)

muffin/trash
============

Adds soft delete support to CakePHP ORM tables.

4.2.2(1mo ago)851.3M—9.6%35[3 issues](https://github.com/UseMuffin/Trash/issues)[1 PRs](https://github.com/UseMuffin/Trash/pulls)11MITPHPPHP &gt;=8.1CI passing

Since Dec 6Pushed 1mo ago10 watchersCompare

[ Source](https://github.com/UseMuffin/Trash)[ Packagist](https://packagist.org/packages/muffin/trash)[ Docs](https://github.com/usemuffin/trash)[ RSS](/packages/muffin-trash/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (26)Used By (11)

Trash
=====

[](#trash)

[![Build Status](https://camo.githubusercontent.com/0bb9ad22e78a5a52d7e40d6f2ff0f3b314bfd369f40fe9f3f49e7c5ed8737cb1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f5573654d756666696e2f54726173682f63692e796d6c3f7374796c653d666c61742d737175617265)](https://github.com/UseMuffin/Trash/actions?query=workflow%3ACI+branch%3Amaster)[![Coverage](https://camo.githubusercontent.com/3331e86897ddb876a8871b0ee8533caa62f18326851b1c36673057c6c3d949dc/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f5573654d756666696e2f54726173682f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/UseMuffin/Trash)[![Total Downloads](https://camo.githubusercontent.com/7fefc55a4e6c13c031dd439d96c3f6ba492d5167c58cd5c4989bedba104bf381/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d756666696e2f74726173682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/muffin/trash)[![License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Adds "soft"-delete support to CakePHP tables.

Install
-------

[](#install)

Using [Composer](http://getcomposer.org):

```
composer require muffin/trash

```

You then need to load the plugin. You can use the shell command:

```
bin/cake plugin load Muffin/Trash

```

Usage
-----

[](#usage)

In your table(s), add the behavior like you would for any other behavior:

```
// in the initialize() method
$this->addBehavior('Muffin/Trash.Trash');
```

By default, the behavior expects your table to have a *nullable* `DATETIME` column named `deleted` or `trashed`. Or you could customize the name when adding the behavior:

```
// in your table's initialize() method
$this->addBehavior('Muffin/Trash.Trash', [
    'field' => 'deleted_at'
]);
```

or, at the global level, in `bootstrap.php`:

```
Configure::write('Muffin/Trash.field', 'deleted_at');
```

Finally, if you would like to keep the default cake behavior when running `find()` or `delete()` operations and explicitly call the behavior when you need 'trash'-ing functionality, just disable the event(s):

```
// in the initialize() method
$this->addBehavior('Muffin/Trash.Trash', [
    'events' => ['Model.beforeFind'] // enables the beforeFind event only, false to disable both
]);
```

or use the purge option:

```
$table->delete($entity, ['purge' => true]);
```

Detecting trashing
------------------

[](#detecting-trashing)

If you need to distinguish between deletion and trashing the behavior adds the \['trash' =&gt; true \] option to the afterDelete event it creates when trashing.

### Cascading deletion

[](#cascading-deletion)

If you'd like to have related records marked as trashed when deleting a parent item, you can just attach the behavior to the related table classes, and set the `'dependent' => true, 'cascadeCallbacks' => true` options in the table relationships.

This works on relationships where the item being deleted in the owning side of the relationship. Which means that the related table should contain the foreign key.

If you don't want to cascade on trash:

```
// in the initialize() method
$this->addBehavior('Muffin/Trash.Trash', [
    'cascadeOnTrash' => false,
]);
```

### Custom Finders

[](#custom-finders)

- **onlyTrashed** - helps getting only those trashed records.
- **withTrashed** - when filtering out the trashed records by default, this method comes in handy to have them included as part of certain calls.

### Extras

[](#extras)

- **emptyTrash()** - permanently deletes all trashed records.
- **restoreTrash($entity = null, array $options = \[\])** - restores one (or all) trashed records.
- **cascadingRestoreTrash($entity = null, array $options = \[\])** - restores one (or all) trashed records including those of dependent associations.
- **trash($entity, array $options = \[\])** - like `delete()` but for a soft-delete (handy when `Model.beforeDelete` is disabled by default).
- **trashAll(array $conditions)** - like `deleteAll()` but for soft-deletes.

Patches &amp; Features
----------------------

[](#patches--features)

- Fork
- Mod, fix
- Test - this is important, so it's not unintentionally broken
- Commit - do not mess with license, todo, version, etc. (if you do change any, bump them into commits of their own that I can ignore when I pull)
- Pull request - bonus point for topic branches

To ensure your PRs are considered for upstream, you MUST follow the CakePHP coding standards.

Bugs &amp; Feedback
-------------------

[](#bugs--feedback)

License
-------

[](#license)

Copyright (c) 2015-present, [Use Muffin](http://usemuffin.com) and licensed under [The MIT License](http://www.opensource.org/licenses/mit-license.php).

###  Health Score

69

—

FairBetter than 100% of packages

Maintenance88

Actively maintained with recent releases

Popularity56

Moderate usage in the ecosystem

Community36

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

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

Every ~171 days

Recently: every ~142 days

Total

23

Last Release

55d ago

Major Versions

1.2.0 → 2.0.02017-10-10

2.1.0 → 3.0.0-beta2019-10-30

2.x-dev → 3.0.0-beta22019-12-22

3.x-dev → 4.0.02023-10-01

PHP version history (2 changes)3.0.0-beta2PHP &gt;=7.2

4.0.0PHP &gt;=8.1

### Community

Maintainers

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

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

---

Top Contributors

[![ADmad](https://avatars.githubusercontent.com/u/142658?v=4)](https://github.com/ADmad "ADmad (86 commits)")[![nicosp](https://avatars.githubusercontent.com/u/4110066?v=4)](https://github.com/nicosp "nicosp (11 commits)")[![JacobAGTyler](https://avatars.githubusercontent.com/u/3827053?v=4)](https://github.com/JacobAGTyler "JacobAGTyler (11 commits)")[![arusinowski](https://avatars.githubusercontent.com/u/1587389?v=4)](https://github.com/arusinowski "arusinowski (7 commits)")[![softius](https://avatars.githubusercontent.com/u/586121?v=4)](https://github.com/softius "softius (6 commits)")[![HavokInspiration](https://avatars.githubusercontent.com/u/5243386?v=4)](https://github.com/HavokInspiration "HavokInspiration (5 commits)")[![jadb](https://avatars.githubusercontent.com/u/33527?v=4)](https://github.com/jadb "jadb (5 commits)")[![Spriz](https://avatars.githubusercontent.com/u/3512268?v=4)](https://github.com/Spriz "Spriz (4 commits)")[![adayth](https://avatars.githubusercontent.com/u/1223929?v=4)](https://github.com/adayth "adayth (2 commits)")[![dakota](https://avatars.githubusercontent.com/u/83255?v=4)](https://github.com/dakota "dakota (2 commits)")[![kolorafa](https://avatars.githubusercontent.com/u/921517?v=4)](https://github.com/kolorafa "kolorafa (2 commits)")[![lorenzo](https://avatars.githubusercontent.com/u/37621?v=4)](https://github.com/lorenzo "lorenzo (2 commits)")[![jorisvaesen](https://avatars.githubusercontent.com/u/4093781?v=4)](https://github.com/jorisvaesen "jorisvaesen (1 commits)")[![eliamariutti](https://avatars.githubusercontent.com/u/40852083?v=4)](https://github.com/eliamariutti "eliamariutti (1 commits)")[![angelxmoreno](https://avatars.githubusercontent.com/u/363479?v=4)](https://github.com/angelxmoreno "angelxmoreno (1 commits)")[![Wouter0100](https://avatars.githubusercontent.com/u/864520?v=4)](https://github.com/Wouter0100 "Wouter0100 (1 commits)")

---

Tags

ormcakephptrashmuffin

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/muffin-trash/health.svg)

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

###  Alternatives

[josegonzalez/cakephp-upload

CakePHP plugin to handle file uploading sans ridiculous automagic

5451.3M9](/packages/josegonzalez-cakephp-upload)[muffin/webservice

Simplistic webservices for CakePHP

88191.0k13](/packages/muffin-webservice)[muffin/slug

Slugging support for CakePHP ORM

38264.8k5](/packages/muffin-slug)[admad/cakephp-sequence

Sequence plugin for CakePHP to maintain ordered list of records

46489.9k6](/packages/admad-cakephp-sequence)[riesenia/cakephp-duplicatable

CakePHP ORM plugin for duplicating entities (including related entities)

51384.5k4](/packages/riesenia-cakephp-duplicatable)[josegonzalez/cakephp-version

CakePHP ORM behavior to allow versioning of records

49145.2k](/packages/josegonzalez-cakephp-version)

PHPackages © 2026

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