public function getResponse() { $this->buildHeader(); $responseData = []; $responseData['status'] = ['http_code' => $this->statusCode, 'type' => $this->status, 'message' => $this->message]; // only if an api key is given if ($this->apiKey) { $responseData['status']['rate_limit'] = RateLimiter::get($this->apiKey->public_key); } $dataObject = []; if ($this->data) { $this->buildPagination($this->data); $dataObject = ['data' => $this->data]; } // only if pagination is needed // if($this->pagination) // { // $responseData['status']['pagination'] = $this->pagination; // } // auto-check for error status codes and log to the db if ($this->statusCode > 400 && $this->apiKey) { $log = new ApiLog(); $log->api_key_id = $this->apiKey->id; $log->status = $this->status; $log->message = $this->message; $log->ip_address = Request::ip(); $log->save(); } $responseData = array_merge($responseData, $dataObject); return Response::json($responseData, $this->statusCode, $this->headers); }