Skip to content

SoftDelete

This trait provides soft delete functionality to a model class.

It allows you to mark a record as deleted without actually deleting it from the database. When a record is marked as deleted, it won't be retrieved in queries unless explicitly requested.

  • Full name: \Zemit\Mvc\Model\Traits\SoftDelete

Properties

skipped

protected $skipped

Methods

initializeSoftDelete

Initializing SoftDelete

public initializeSoftDelete(?array $options = null): void

Parameters:

Parameter Type Description
$options ?array

setSoftDeleteBehavior

Set the SoftDeleteBehavior variable Attach the SoftDelete behavior class

public setSoftDeleteBehavior(\Zemit\Mvc\Model\Behavior\SoftDelete $softDeleteBehavior): void

Parameters:

Parameter Type Description
$softDeleteBehavior \Zemit\Mvc\Model\Behavior\SoftDelete

getSoftDeleteBehavior

Return the soft delete behavior instance

public getSoftDeleteBehavior(): \Zemit\Mvc\Model\Behavior\SoftDelete

disableSoftDelete

Disable the soft delete for the current instance Note: Zemit SoftDelete behavior must be attached

public disableSoftDelete(): void

enableSoftDelete

Enable the soft delete for the current instance Note: Zemit SoftDelete behavior must be attached

public enableSoftDelete(): void

isDeleted

Helper method to check if the row is soft deleted

public isDeleted(?string $field = null, ?int $deletedValue = null): bool

Parameters:

Parameter Type Description
$field ?string
$deletedValue ?int

restore

Restore a previously Soft-deleted entry and fire events Events: - beforeRestore - notRestored - afterRestore

public restore(?string $field = null, ?int $notDeletedValue = null): bool

Parameters:

Parameter Type Description
$field ?string
$notDeletedValue ?int