コード例 #1
0
 /**
  * Update a entity in repository by id
  *
  * @throws ValidatorException
  *
  * @param array $attributes
  * @param       $id
  *
  * @return mixed
  */
 public function update(array $attributes, $id)
 {
     $this->applyScope();
     if (!is_null($this->validator)) {
         // we should pass data that has been casts by the model
         // to make sure data type are same because validator may need to use
         // this data to compare with data that fetch from database.
         $attributes = $this->model->newInstance()->forceFill($attributes)->toArray();
         $this->validator->with($attributes)->setId($id)->passesOrFail(ValidatorInterface::RULE_UPDATE);
     }
     $temporarySkipPresenter = $this->skipPresenter;
     $this->skipPresenter(true);
     $model = $this->model->findOrFail($id);
     $model->fill($attributes);
     $model->save();
     $this->skipPresenter($temporarySkipPresenter);
     $this->resetModel();
     event(new RepositoryEntityUpdated($this, $model));
     return $this->parserResult($model);
 }