From c1bd63c0efcccddceb2f2ef0e900d4fb39cee321 Mon Sep 17 00:00:00 2001 From: Mauricio Rodrigues Date: Fri, 4 Nov 2016 23:26:25 -0300 Subject: [PATCH] add fill method --- .../Repositories/Eloquent/Repository.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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(); + } }