Пример #1
0
 private function makeResponse()
 {
     if ($this->http_status_code != HttpStatusCode::CODE_200_OK) {
         $this->body = ArrayHelper::recursive_filter($this->body);
     }
     $this->body['meta'] = $this->meta;
     $this->body['jsonapi'] = ['version' => $this->api_version];
     return new JsonResponse($this->body, $this->http_status_code, $this->header, $this->options);
 }
Пример #2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return PaulVL\JsonApi\Response
  */
 public function update(Request $request, $id)
 {
     $class = $this->model_class;
     $response = new Response();
     $object = $class::findOrFail($id);
     $inputs = ArrayHelper::empty_to_null($request->all());
     $validator = Validator::make($inputs, $object->getUpdateRules());
     if ($validator->fails()) {
         $validation_errors = StringHelper::concatInOneLine($validator->errors()->all(), ' ');
         return $response->responseUnprocessableEntity($validation_errors);
     }
     if (method_exists($this, 'updateData')) {
         return $this->updateData($object, $inputs);
     } else {
         try {
             $updated_rows = $class::where($object->getKeyName(), $object->getKey())->update($inputs);
             $object = $class::findOrFail($id);
             $response->handleData($object);
             return $response->response();
         } catch (Exception $e) {
             return $response->responseInternalServerError();
         }
     }
 }