PHPackages                             alusev/cakephp-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. [Framework](/categories/framework)
4. /
5. alusev/cakephp-soft-delete

ActiveCakephp-plugin[Framework](/categories/framework)

alusev/cakephp-soft-delete
==========================

SoftDelete plugin for CakePHP

2.0.1(6y ago)01.2kMITPHPPHP &gt;=7.2

Since Feb 1Pushed 6y agoCompare

[ Source](https://github.com/alusev/cakephp-soft-delete)[ Packagist](https://packagist.org/packages/alusev/cakephp-soft-delete)[ Docs](https://github.com/alusev/cakephp-soft-delete)[ RSS](/packages/alusev-cakephp-soft-delete/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (13)Used By (0)

CakeSoftDelete plugin for CakePHP
=================================

[](#cakesoftdelete-plugin-for-cakephp)

[![Build Status](https://camo.githubusercontent.com/076e7880cdd860b363871ae05d039ecb6f577499a7877e80e31e49db0d7e353f/68747470733a2f2f7472617669732d63692e6f72672f616c757365762f63616b657068702d736f66742d64656c6574652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/alusev/cakephp-soft-delete)

This is a fork of PGBI/cakephp3-soft-delete

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` timestamp is set on the record.

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

[](#requirements)

This plugins has been developed for cakephp 4.x.

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 ealus/cakephp-soft-delete

```

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

[](#configuration)

### Load the plugin:

[](#load-the-plugin)

```
// In /config/bootstrap.php
Plugin::load('SoftDelete');

```

### 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;
    ...

```

Your soft deletable model database table should have a field called `deleted` of type DateTime with NULL as default value. If you want to customise this field you can declare the field in your Table class.

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

class UsersTable extends Table
{
    use SoftDeleteTrait;

    protected $softDeleteField = 'deleted_date';
    ...
```

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

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 57.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 ~164 days

Recently: every ~428 days

Total

12

Last Release

2311d ago

Major Versions

0.1.2 → 1.0.02015-03-22

1.3.0 → 2.0.02020-01-11

PHP version history (2 changes)0.1.0PHP &gt;=5.4

2.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/960a011109832fc2a173c2b30207cfb94213b1c4d55825e547953827ccb7447d?d=identicon)[latenal](/maintainers/latenal)

---

Top Contributors

[![PGBI](https://avatars.githubusercontent.com/u/6191583?v=4)](https://github.com/PGBI "PGBI (23 commits)")[![alusev](https://avatars.githubusercontent.com/u/903378?v=4)](https://github.com/alusev "alusev (8 commits)")[![davidyell](https://avatars.githubusercontent.com/u/49889?v=4)](https://github.com/davidyell "davidyell (7 commits)")[![gauravmak](https://avatars.githubusercontent.com/u/11887260?v=4)](https://github.com/gauravmak "gauravmak (1 commits)")[![ravage84](https://avatars.githubusercontent.com/u/625761?v=4)](https://github.com/ravage84 "ravage84 (1 commits)")

---

Tags

plugincakephpdeletesoftdeletablecakephp 4

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alusev-cakephp-soft-delete/health.svg)

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

###  Alternatives

[pgbi/cakephp3-soft-delete

SoftDelete plugin for CakePHP

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

Bake plugin for CakePHP

11211.2M156](/packages/cakephp-bake)[cakephp/acl

Acl Plugin for CakePHP framework

109553.9k15](/packages/cakephp-acl)[cakedc/mixer

A plugin to discover and manage CakePHP plugins and generate skeleton application code.

4521.2k1](/packages/cakedc-mixer)

PHPackages © 2026

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