diff --git a/laravel/database/eloquent/relationships/has_many_and_belongs_to.php b/laravel/database/eloquent/relationships/has_many_and_belongs_to.php index 1c0d3e03..7dc8b0a3 100644 --- a/laravel/database/eloquent/relationships/has_many_and_belongs_to.php +++ b/laravel/database/eloquent/relationships/has_many_and_belongs_to.php @@ -121,6 +121,7 @@ public function detach($ids) public function sync($ids) { $current = $this->pivot()->lists($this->other_key()); + $ids = (array) $ids; // First we need to attach any of the associated models that are not currently // in the joining table. We'll spin through the given IDs, checking to see @@ -140,7 +141,7 @@ public function sync($ids) if (count($detach) > 0) { - $this->detach(array_diff($current, $ids)); + $this->detach($detach); } }