notification()['title'] ? $this->notification()['title']: Notifications::UNDEFINED['title']; } /** * @return string */ private function getNotificationMessage():string { return $this->notification()['message'] ? $this->notification()['message']: Notifications::UNDEFINED['message']; } /** * @param Request $request * @return BinaryFileResponse * @throws ErrorException */ abstract protected function logic(Request $request) : BinaryFileResponse; /** * @param Request $request * @return BinaryFileResponse */ public function execute(Request $request) : BinaryFileResponse { try { DB::beginTransaction(); $response = $this->logic($request); DB::commit(); return $response; } catch (ErrorException|GeneralExceptions|TypeError $exception){ abort(404, $exception->getMessage()); } } /** * @param array|null $data * @return JsonResponse */ public function response(?array $data = []) : JsonResponse { return (new ApiResponseObject($this->getNotificationTitle().' Successful', $this->getNotificationMessage(), HttpStatus::OK_WITH_MESSAGE, $data))->handler(); } /** * @param JsonResource $resource * @return JsonResponse */ public function resourceResponse(JsonResource $resource){ return $this->response(['data' => $resource]); } /** * @param ResourceCollection $collection * @return JsonResponse */ public function collectionResponse(ResourceCollection $collection){ return $this->response(json_decode($collection->response()->getContent(), true)); } }