Skip to content

Commit

Permalink
Enloquent new function sync
Browse files Browse the repository at this point in the history
  • Loading branch information
eullercdr committed Mar 5, 2017
1 parent f27bdf6 commit ae9e9eb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/Prettus/Repository/Contracts/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
28 changes: 21 additions & 7 deletions src/Prettus/Repository/Eloquent/BaseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,22 @@ 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
*/
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
Expand All @@ -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
*
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -634,7 +648,7 @@ public function with($relations)

return $this;
}

/**
* Load relation with closure
*
Expand Down

0 comments on commit ae9e9eb

Please sign in to comment.