PHPackages                             tuliocaique/softdelete - 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. tuliocaique/softdelete

ActiveCakephp-plugin

tuliocaique/softdelete
======================

SoftDelete plugin for CakePHP

2.3(6mo ago)0134MITPHPPHP &gt;=7.2

Since Sep 5Pushed 6mo ago1 watchersCompare

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

READMEChangelog (3)Dependencies (3)Versions (5)Used By (0)

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

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

[![Build status](https://camo.githubusercontent.com/de40fb6b5f5eacfc5b4909c5b34d540813254f8ebb9e34527e47a881dee61135/68747470733a2f2f6170692e7472617669732d63692e6f72672f504742492f63616b65706870332d736f66742d64656c6574652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/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 3.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 pgbi/cakephp3-soft-delete "~1.0"

```

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

34

—

LowBetter than 77% of packages

Maintenance66

Regular maintenance activity

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

Every ~378 days

Total

4

Last Release

207d ago

Major Versions

1.0.1 → 2.02022-09-05

### Community

Maintainers

![](https://www.gravatar.com/avatar/4ef6dfcca2cf677a02eb2ff436ea6126a18259187c5edaa56fa52609202fe433?d=identicon)[tuliocaique](/maintainers/tuliocaique)

---

Top Contributors

[![tuliocaique](https://avatars.githubusercontent.com/u/22997899?v=4)](https://github.com/tuliocaique "tuliocaique (5 commits)")

---

Tags

plugincakephpdeletesoftdeletablecakephp 4

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tuliocaique-softdelete/health.svg)

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

###  Alternatives

[pgbi/cakephp3-soft-delete

SoftDelete plugin for CakePHP

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

A CakePHP plugin to handle user authentication and authorization the easy way.

129228.6k10](/packages/dereuromark-cakephp-tinyauth)[dereuromark/cakephp-databaselog

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

44165.0k2](/packages/dereuromark-cakephp-databaselog)[ivanamat/cakephp3-aclmanager

AclManager plugin for CakePHP 3.x

2715.2k](/packages/ivanamat-cakephp3-aclmanager)[dereuromark/cakephp-translate

A CakePHP plugin for managing translations

1710.4k](/packages/dereuromark-cakephp-translate)

PHPackages © 2026

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