public function delete($id) { try { //fetch the entity $entity = $this->gateway->findByPk($id); if (!$entity) { return $this->payload->notFound(['id' => $id]); } //delete the entity if (!$this->gateway->delete($entity)) { return $this->payload->notDeleted([$this->entityName => $entity]); } //success return $this->payload->deleted([$this->entityName => $entity]); } catch (\Exception $e) { return $this->payload->error(['exception' => $e, $this->entityName => $entity]); } }