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

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

vandalorumrex/trash
===================

Adds soft delete support to CakePHP ORM tables.

v4.2.2(8mo ago)0102MITPHPPHP &gt;=8.1

Since Apr 15Pushed 8mo agoCompare

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

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

Trash
=====

[](#trash)

[![License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Adds "soft"-delete support to CakePHP tables.

Install
-------

[](#install)

Using \[Composer\]\[composer\]:

```
composer require vandalorumrex/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)

This library is license under the MIT License (MIT). Please see License File for more information.

Credits
-------

[](#credits)

This library was forked from [UseMuffin Trash's](https://github.com/UseMuffin) on Github .

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance60

Regular maintenance activity

Popularity10

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 56.3% 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 ~135 days

Total

2

Last Release

263d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0718ee6a9562679d6fa001109fde0c93f163b7cc679d90801b00ba33f2bfc1e6?d=identicon)[VandalorumRex](/maintainers/VandalorumRex)

---

Top Contributors

[![ADmad](https://avatars.githubusercontent.com/u/142658?v=4)](https://github.com/ADmad "ADmad (81 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)")[![jadb](https://avatars.githubusercontent.com/u/33527?v=4)](https://github.com/jadb "jadb (5 commits)")[![HavokInspiration](https://avatars.githubusercontent.com/u/5243386?v=4)](https://github.com/HavokInspiration "HavokInspiration (5 commits)")[![VandalorumRex](https://avatars.githubusercontent.com/u/12428558?v=4)](https://github.com/VandalorumRex "VandalorumRex (4 commits)")[![Spriz](https://avatars.githubusercontent.com/u/3512268?v=4)](https://github.com/Spriz "Spriz (4 commits)")[![dakota](https://avatars.githubusercontent.com/u/83255?v=4)](https://github.com/dakota "dakota (2 commits)")[![lorenzo](https://avatars.githubusercontent.com/u/37621?v=4)](https://github.com/lorenzo "lorenzo (2 commits)")[![adayth](https://avatars.githubusercontent.com/u/1223929?v=4)](https://github.com/adayth "adayth (2 commits)")[![Wouter0100](https://avatars.githubusercontent.com/u/864520?v=4)](https://github.com/Wouter0100 "Wouter0100 (1 commits)")[![eliamariutti](https://avatars.githubusercontent.com/u/40852083?v=4)](https://github.com/eliamariutti "eliamariutti (1 commits)")[![jorisvaesen](https://avatars.githubusercontent.com/u/4093781?v=4)](https://github.com/jorisvaesen "jorisvaesen (1 commits)")[![kolorafa](https://avatars.githubusercontent.com/u/921517?v=4)](https://github.com/kolorafa "kolorafa (1 commits)")

---

Tags

ormcakephptrashvandalorumrex

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[muffin/trash

Adds soft delete support to CakePHP ORM tables.

851.3M11](/packages/muffin-trash)[josegonzalez/cakephp-upload

CakePHP plugin to handle file uploading sans ridiculous automagic

5451.3M9](/packages/josegonzalez-cakephp-upload)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58523.9M36](/packages/scienta-doctrine-json-functions)[muffin/webservice

Simplistic webservices for CakePHP

88191.0k13](/packages/muffin-webservice)[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)

PHPackages © 2026

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