// Created on savesnippets.com ยท https://savesnippets.com/UEHJenFfDfzvw9 db->prepare("SELECT * FROM {$this->table} WHERE id=? AND deleted_at IS NULL"); $s->execute([$id]); return $s->fetch() ?: null; } public function all(): array { return $this->db->query("SELECT * FROM {$this->table} WHERE deleted_at IS NULL")->fetchAll(); } public function softDelete(int $id): void { $this->db->prepare("UPDATE {$this->table} SET deleted_at = NOW() WHERE id=? AND deleted_at IS NULL") ->execute([$id]); } public function restore(int $id): void { $this->db->prepare("UPDATE {$this->table} SET deleted_at = NULL WHERE id=?")->execute([$id]); } } $users = new SoftDeleteRepo($db, 'users'); $users->softDelete(42); // keeps the row, hides it from find/all