What is CodeIgniter 4 soft deletes?
Answer
CodeIgniter 4 models support soft deletes — marking records as deleted without removing them from the database. Enable in your model: protected $useSoftDeletes = true and set protected $deletedField = "deleted_at". Add a nullable deleted_at DATETIME column to your migration. Calling $this->model->delete($id) sets deleted_at to the current timestamp. Normal queries (findAll(), where()) automatically exclude soft-deleted records. Include deleted records: $this->model->withDeleted()->findAll(). Show only deleted: $this->model->onlyDeleted()->findAll(). Restore a record: $this->model->delete($id, false) does a hard delete; to restore, manually update deleted_at to null. Soft deletes are useful for audit trails, trash functionality, and accidentally deleted record recovery.
Previous
What is CodeIgniter 4 response API trait?
Next
What is the Session driver configuration in CodeIgniter 4?