Download the PHP package aokazu/cakephp4-soft-delete without Composer
On this page you can find all versions of the php package aokazu/cakephp4-soft-delete. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package cakephp4-soft-delete
CakeSoftDelete plugin for Cakephp4.* (Upgrade for CakePHP2's SoftDeletableBehavior)
Fork
This repo is forked from not maintained salines/cakephp4-soft-delete and updated to avoid deprecated code in CakePHP >=4.0
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
This Trait has been developed for cakephp >=4.0 and PHP >=8.0
Installation
You can install this plugin into your CakePHP application using composer.
Update your composer file to include this plugin:
Configuration
Make a model soft deleteable:
Use the SoftDelete trait on your model Table class:
Use
Soft deleting records
delete
and deleteAll
functions will now soft delete records by populating deleted
field with the date of the deletion.
Restoring Soft deleted records
To restore a soft deleted entity into an active state, use the restore
method:
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:
Hard deleting records
To hard delete a single entity:
To mass hard delete records that were soft deleted before a given date, you can use hardDeleteAll($date):
Soft deleting & associations
Associations are correctly handled by SoftDelete plugin.
- Soft deletion will be cascaded to related models as usual. If related models also use SoftDelete Trait, they will be soft deleted.
- Soft deletes records will be excluded from counter caches.