diff --git a/src/Prettus/Repository/Contracts/RepositoryInterface.php b/src/Prettus/Repository/Contracts/RepositoryInterface.php index 34fa31e0..efe2c758 100644 --- a/src/Prettus/Repository/Contracts/RepositoryInterface.php +++ b/src/Prettus/Repository/Contracts/RepositoryInterface.php @@ -28,6 +28,16 @@ public function lists($column, $key = null); */ public function pluck($column, $key = null); + /** + * Sync relations + * + * @param $id + * @param $relation + * @param array $attributes + * @return $this + */ + public function sync($relation, $attributes); + /** * Retrieve all data of repository * diff --git a/src/Prettus/Repository/Eloquent/BaseRepository.php b/src/Prettus/Repository/Eloquent/BaseRepository.php index d730e110..c36eaaed 100644 --- a/src/Prettus/Repository/Eloquent/BaseRepository.php +++ b/src/Prettus/Repository/Eloquent/BaseRepository.php @@ -255,7 +255,7 @@ public function scopeQuery(\Closure $scope) /** * Retrieve data array for populate field select * - * @param string $column + * @param string $column * @param string|null $key * * @return \Illuminate\Support\Collection|array @@ -263,14 +263,14 @@ public function scopeQuery(\Closure $scope) public function lists($column, $key = null) { $this->applyCriteria(); - + return $this->model->lists($column, $key); } /** * Retrieve data array for populate field select * Compatible with Laravel 5.3 - * @param string $column + * @param string $column * @param string|null $key * * @return \Illuminate\Support\Collection|array @@ -282,6 +282,20 @@ public function pluck($column, $key = null) return $this->model->pluck($column, $key); } + /** + * Sync relations + * + * @param $id + * @param $relation + * @param array $attributes + * @return $this + */ + public function sync($relation, $attributes) + { + $this->model = $this->model->with($relation)->getRelation($relation)->sync($attributes); + return $this; + } + /** * Retrieve all data of repository * @@ -329,8 +343,8 @@ public function first($columns = ['*']) /** * Retrieve all data of repository, paginated * - * @param null $limit - * @param array $columns + * @param null $limit + * @param array $columns * @param string $method * * @return mixed @@ -350,7 +364,7 @@ public function paginate($limit = null, $columns = ['*'], $method = "paginate") /** * Retrieve all data of repository, simple paginated * - * @param null $limit + * @param null $limit * @param array $columns * * @return mixed @@ -634,7 +648,7 @@ public function with($relations) return $this; } - + /** * Load relation with closure *