Skip to content

Commit 110b129

Browse files
committed
fix
1 parent a10552d commit 110b129

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Illuminate/Database/Eloquent/Relations/MorphToMany.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Database\Eloquent\Builder;
66
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\Relations\MorphPivot;
78
use Illuminate\Support\Arr;
89

910
class MorphToMany extends BelongsToMany
@@ -123,8 +124,10 @@ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery,
123124
protected function getCurrentlyAttachedPivots()
124125
{
125126
return parent::getCurrentlyAttachedPivots()->map(function ($record) {
126-
return $record->setMorphType($this->morphType)
127-
->setMorphClass($this->morphClass);
127+
return $record instanceof MorphPivot
128+
? $record->setMorphType($this->morphType)
129+
->setMorphClass($this->morphClass)
130+
: $record;
128131
});
129132
}
130133

0 commit comments

Comments
 (0)