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 JsonResponse * @throws ErrorException */ abstract protected function logic(Request $request) : JsonResponse; /** * @param Request $request * @return JsonResponse */ public function execute(Request $request) : JsonResponse { try { if(Auth::user()){ if(Auth::user()->type === 3) UserRiskAnalysis::dispatch(Auth::user(), $request->header('captcha-token')); } DB::beginTransaction(); $response = $this->logic($request); DB::commit(); return $response; } catch (ErrorException|GeneralExceptions $exception){ if ($exception instanceof JobResourceNotFoundException) { Log::error(sprintf( "Uncaught exception '%s' with message '%s' in %s:%d", get_class($exception), $exception->getMessage(), $exception->getTrace()[0]['file'], $exception->getTrace()[0]['line'] )); } else{ log::error($exception); } return (new ApiResponseObject($this->getNotificationTitle().' failed', $exception->getMessage(), $exception->getCode() ? $exception->getCode() : HttpStatus::SERVER_ERROR))->handler(); } } /** * @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)); } }