Download the PHP package 40katty04/cakephp4-soft-delete without Composer
On this page you can find all versions of the php package 40katty04/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 CakePHP
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
This plugins has been developed for cakephp 4.x.
Installation
You can install this plugin into your CakePHP application using composer.
Update your composer file to include this plugin:
Configuration
Load the plugin:
Make a model soft deleteable:
Use the SoftDelete trait on your model Table class:
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.
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.