PHPackages                             aokazu/cakephp4-soft-delete - 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. aokazu/cakephp4-soft-delete

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

aokazu/cakephp4-soft-delete
===========================

SoftDelete plugin updated for CakePHP 4

2.0.3(4y ago)016MITPHPPHP &gt;=7.2

Since Jan 31Pushed 4y agoCompare

[ Source](https://github.com/aokazu/cakephp4-soft-delete)[ Packagist](https://packagist.org/packages/aokazu/cakephp4-soft-delete)[ Docs](https://github.com/aokazu/cakephp4-soft-delete)[ RSS](/packages/aokazu-cakephp4-soft-delete/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (3)Versions (10)Used By (0)

CakeSoftDelete plugin for Cakephp4.\* (Upgrade for CakePHP2's SoftDeletableBehavior)
====================================================================================

[](#cakesoftdelete-plugin-for-cakephp4-upgrade-for-cakephp2s-softdeletablebehavior)

Fork
----

[](#fork)

This repo is forked from not maintained [salines/cakephp4-soft-delete](https://github.com/salines/cakephp4-soft-delete) and updated to avoid deprecated code in CakePHP &gt;=4.0

Purpose
-------

[](#purpose)

This Cakephp plugin enables you to make your models soft deletable. When soft deleting an entity, it is not actually removed from your database. Instead, a `deleted` int2 is set 1 on the record. AND a `deleted_date` timestamp as string is set on the record.(`deleted_date` Default ='0')

Requirements
------------

[](#requirements)

This Trait has been developed for cakephp &gt;=4.0 and PHP &gt;=8.0

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

[](#installation)

You can install this plugin into your CakePHP application using [composer](http://getcomposer.org).

Update your composer file to include this plugin:

```
composer require aokazu/cakephp4-soft-delete "2.*"

```

Configuration
-------------

[](#configuration)

### Make a model soft deleteable:

[](#make-a-model-soft-deleteable)

Use the SoftDelete trait on your model Table class:

```
// in src/Model/Table/UsersTable.php
...
use SoftDelete\Model\Table\SoftDeleteTrait;

class UsersTable extends Table
{
    use SoftDeleteTrait;
    ...

```

Use
---

[](#use)

### Soft deleting records

[](#soft-deleting-records)

`delete` and `deleteAll` functions will now soft delete records by populating `deleted` field with the date of the deletion.

```
// in src/Model/Table/UsersTable.php
$this->delete($user); // $user entity is now soft deleted if UsersTable uses SoftDeleteTrait.
```

### Restoring Soft deleted records

[](#restoring-soft-deleted-records)

To restore a soft deleted entity into an active state, use the `restore` method:

```
// in src/Model/Table/UsersTable.php
// Let's suppose $user #1 is soft deleted.
$user = $this->Users->find('all', ['withDeleted'])->where('id', 1)->first();
$this->restore($user); // $user #1 is now restored.
```

### Finding records

[](#finding-records)

`find`, `get` or dynamic finders (such as `findById`) will only return non soft deleted records. To also return soft deleted records, `$options` must contain `'withDeleted'`. Example:

```
// in src/Model/Table/UsersTable.php
$nonSoftDeletedRecords = $this->find('all');
$allRecords            = $this->find('all', ['withDeleted']);
```

### Hard deleting records

[](#hard-deleting-records)

To hard delete a single entity:

```
// in src/Model/Table/UsersTable.php
$user = $this->get($userId);
$success = $this->hardDelete($user);
```

To mass hard delete records that were soft deleted before a given date, you can use hardDeleteAll($date):

```
// in src/Model/Table/UsersTable.php
$date = new \DateTime('some date');
$affectedRowsCount = $this->hardDeleteAll($date);

```

Soft deleting &amp; associations
--------------------------------

[](#soft-deleting--associations)

Associations are correctly handled by SoftDelete plugin.

1. Soft deletion will be cascaded to related models as usual. If related models also use SoftDelete Trait, they will be soft deleted.
2. Soft deletes records will be excluded from counter caches.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% 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 ~67 days

Recently: every ~84 days

Total

9

Last Release

1758d ago

Major Versions

1.0.4 → 2.02021-06-16

### Community

Maintainers

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

---

Top Contributors

[![aokazu](https://avatars.githubusercontent.com/u/147267?v=4)](https://github.com/aokazu "aokazu (7 commits)")[![nparadzik](https://avatars.githubusercontent.com/u/65295766?v=4)](https://github.com/nparadzik "nparadzik (4 commits)")[![salines](https://avatars.githubusercontent.com/u/343737?v=4)](https://github.com/salines "salines (2 commits)")[![JoshaMunnik](https://avatars.githubusercontent.com/u/1231100?v=4)](https://github.com/JoshaMunnik "JoshaMunnik (1 commits)")

---

Tags

plugincakephpdeletesoftdeletablecakephp 4

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/aokazu-cakephp4-soft-delete/health.svg)

```
[![Health](https://phpackages.com/badges/aokazu-cakephp4-soft-delete/health.svg)](https://phpackages.com/packages/aokazu-cakephp4-soft-delete)
```

###  Alternatives

[pgbi/cakephp3-soft-delete

SoftDelete plugin for CakePHP

87291.9k](/packages/pgbi-cakephp3-soft-delete)[dereuromark/cakephp-databaselog

A CakePHP plugin for storing and viewing application logs in the database

44165.0k2](/packages/dereuromark-cakephp-databaselog)[xety/cake3-upload

Cake3 plugin to upload files.

2825.6k1](/packages/xety-cake3-upload)[itosho/easy-query

CakePHP behavior plugin for easily generating some complicated queries like (bulk) insert/upsert etc.

2623.2k](/packages/itosho-easy-query)

PHPackages © 2026

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