request = $request; $this->destinationService = $destinationService; } public function searchDestination(Request $request) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { if (is_null($this->request->getContent())) { throw new ApiErrorException(lang('Parameter Error.')); } $params = $this->request->params; $requestParams = [ 'locale' => fillOnUndefined($params, 'locale'), 'search_term' => fillOnUndefined($params, 'search_term'), 'user_id' => $request->credentials->user_id, ]; $destinationSearch = $this->destinationService->searchDestination($requestParams); if($destinationSearch['status'] != 'success'){ throw new ApiErrorException($destinationSearch['message']); } $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $destinationSearch['data']]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } }