diff --git a/src/Relations/BelongsToMany.php b/src/Relations/BelongsToMany.php index 2352adc50..656043eaf 100644 --- a/src/Relations/BelongsToMany.php +++ b/src/Relations/BelongsToMany.php @@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Model as EloquentModel; use Illuminate\Database\Eloquent\Relations\BelongsToMany as EloquentBelongsToMany; use Illuminate\Support\Arr; +use Jenssegers\Mongodb\Eloquent\Model as MongodbModel; class BelongsToMany extends EloquentBelongsToMany { @@ -122,7 +123,9 @@ public function sync($ids, $detaching = true) if ($ids instanceof Collection) { $ids = $ids->modelKeys(); - } + } elseif ($ids instanceof MongodbModel) { + $ids = [$ids->{$this->relatedKey}]; + } // First we need to attach any of the associated models that are not currently // in this joining table. We'll spin through the given IDs, checking to see