Skip to content

Commit

Permalink
Fixed sync relations
Browse files Browse the repository at this point in the history
  • Loading branch information
eullercdr committed Mar 9, 2017
1 parent baa74a8 commit bf1f3b1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/Prettus/Repository/Contracts/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ public function pluck($column, $key = null);
/**
* Sync relations
*
* @param $id
* @param $relation
* @param array $attributes
* @return $this
* @param boolean $detaching
* @return array
*/
public function sync($relation, $attributes);
public function sync($id, $relation, $attributes, $detaching = true);

/**
* Retrieve all data of repository
Expand Down
9 changes: 5 additions & 4 deletions src/Prettus/Repository/Eloquent/BaseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,15 @@ public function pluck($column, $key = null)
/**
* Sync relations
*
* @param $id
* @param $relation
* @param array $attributes
* @return $this
* @param boolean $detaching
* @return array
*/
public function sync($relation, $attributes)
public function sync($id, $relation, $attributes, $detaching = true)
{
$this->model = $this->model->with($relation)->getRelation($relation)->sync($attributes);
return $this;
return $this->find($id)->getRelation($relation)->sync($attributes, $detaching);
}

/**
Expand Down

0 comments on commit bf1f3b1

Please sign in to comment.