// codeigniter 4 delete with redirect data
public function deletePet($id) {
$pet = new Pets(); // Model
$pet->delete($id); // delete data using id
return redirect()->to('/user/pets')->with('success', 'Pet deleted successfully');
}
//display the " ->with() in front-end
<?php if(session()->get('success')): ?>
<div class="alert alert-success" role="alert">
<?= session()->get('success') ?>
</div>
<?php endif; ?>