I have a problem with CodeIgniter 4 Soft Delete. I've set $useSoftDelete = true in the model; but whenever i delete a record, the delete method always purge it from my table.
Here is the code in my model :
// Dates
protected $useTimestamps = true;
protected $useSoftDelete = true;
protected $dateFormat = 'datetime';
protected $createdField = 'cust_created_at';
protected $updatedField = 'cust_updated_at';
protected $deletedField = 'cust_deleted_at';
Here is my delete method in my controller :
public function delete($id = '')
{
$customer = $this->customerModel->find($id);
if (isset($customer)) {
$this->customerModel->delete($id);
session()->setFlashdata('success', "Customer $customer->cust_name successfully deleted.");
return redirect()->to(site_url('customer'));
} else {
session()->setFlashdata('errors', ["Cannot find customer ID $id."]);
return redirect()->to(site_url('customer'));
}
}
Any code I missed? Thank you in advance.
Typo in
protected $useSoftDelete = true;
.
it should be
protected $useSoftDeletes = true;
Ref: https://codeigniter4.github.io/userguide/models/model.html#configuring-your-model