diff --git a/src/BelongsToMany.php b/src/BelongsToMany.php index 15e0a4e..425e5dd 100644 --- a/src/BelongsToMany.php +++ b/src/BelongsToMany.php @@ -105,7 +105,7 @@ public function attach($id, array $attributes = [], $touch = true) public function detach($ids = null, $touch = true) { // Get detached ids to pass them to event - $ids = $ids ?? $this->parent->{$this->getRelationName()}->pluck('id'); + $ids = $ids ?? $this->parent->{$this->getRelationName()}->pluck($this->relatedKey); $this->parent->fireModelBelongsToManyEvent('detaching', $this->getRelationName(), $ids); diff --git a/src/MorphToMany.php b/src/MorphToMany.php index 3ebe448..e3628f8 100644 --- a/src/MorphToMany.php +++ b/src/MorphToMany.php @@ -103,7 +103,7 @@ public function attach($id, array $attributes = [], $touch = true) public function detach($ids = null, $touch = true) { // Get detached ids to pass them to event - $ids = $ids ?? $this->parent->{$this->getRelationName()}->pluck('id'); + $ids = $ids ?? $this->parent->{$this->getRelationName()}->pluck($this->relatedKey); $this->parent->fireModelMorphToManyEvent('detaching', $this->getRelationName(), $ids); diff --git a/src/MorphedByMany.php b/src/MorphedByMany.php index b932b39..e7303c7 100644 --- a/src/MorphedByMany.php +++ b/src/MorphedByMany.php @@ -103,7 +103,7 @@ public function attach($id, array $attributes = [], $touch = true) public function detach($ids = null, $touch = true) { // Get detached ids to pass them to event - $ids = $ids ?? $this->parent->{$this->getRelationName()}->pluck('id'); + $ids = $ids ?? $this->parent->{$this->getRelationName()}->pluck($this->relatedKey); $this->parent->fireModelMorphedByManyEvent('detaching', $this->getRelationName(), $ids);