public function buildResponse() { parent::buildResponse(); if (!$this->model->exists()) { throw $this->modelNotFoundError(); } if (!$this->hasPermission()) { throw $this->permissionError(); } if ($this->model->delete()) { $this->response->setCode(204); return; } // get the first error if ($error = $this->getFirstError()) { throw $this->modelValidationError($error); } // no specific errors available, throw a generic error throw new ApiError('There was an error deleting the ' . $this->humanClassName($this->model) . '.'); }
public function buildResponse() { if (!is_array($this->createParameters)) { throw new InvalidRequest('Unable to parse request body.'); } parent::buildResponse(); if (!$this->hasPermission()) { throw $this->permissionError(); } if ($this->model->create($this->createParameters)) { $this->response->setCode(201); return $this->model; } // get the first error if ($error = $this->getFirstError()) { throw $this->modelValidationError($error); } // no specific errors available, throw a server error throw new ApiError('There was an error creating the ' . $this->humanClassName($this->model) . '.'); }
public function buildResponse() { if (!is_array($this->updateParameters)) { throw new InvalidRequest('Unable to parse request body.'); } parent::buildResponse(); if (!$this->model->exists()) { throw $this->modelNotFoundError(); } if (!$this->hasPermission()) { throw $this->permissionError(); } if ($this->model->set($this->updateParameters)) { return $this->model; } // get the first error if ($error = $this->getFirstError()) { throw $this->modelValidationError($error); } // no specific errors available, throw a generic one throw new ApiError('There was an error updating the ' . $this->humanClassName($this->model) . '.'); }
public function buildResponse() { parent::buildResponse(); if (!$this->hasPermission()) { throw $this->permissionError(); } $query = $this->buildQuery(); $models = $query->execute(); $model = $this->model; $total = $model::totalRecords($query->getWhere()); $this->paginate($this->page, $this->perPage, $total); return $models; }