diff --git a/src/Bosnadev/Repositories/Eloquent/Repository.php b/src/Bosnadev/Repositories/Eloquent/Repository.php index 303fe46..7447b8e 100644 --- a/src/Bosnadev/Repositories/Eloquent/Repository.php +++ b/src/Bosnadev/Repositories/Eloquent/Repository.php @@ -344,4 +344,23 @@ public function applyCriteria() return $this; } + + /** + * Fill attributes data before saving. + * + * @param array $data + * @param $id + * @return mixed + * @throws ModelNotFoundException + */ + public function fill(array $data, $id) + { + $model = $this->makeModel()->find($id); + + if (! $model) { + throw new ModelNotFoundException("Model '" . $this->model() . "' with id ${id} not found."); + } + + return $model->fill($data)->save(); + } }