Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jun 2, 2020
1 parent a10552d commit 110b129
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Illuminate/Database/Eloquent/Relations/MorphToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphPivot;
use Illuminate\Support\Arr;

class MorphToMany extends BelongsToMany
Expand Down Expand Up @@ -123,8 +124,10 @@ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery,
protected function getCurrentlyAttachedPivots()
{
return parent::getCurrentlyAttachedPivots()->map(function ($record) {
return $record->setMorphType($this->morphType)
->setMorphClass($this->morphClass);
return $record instanceof MorphPivot
? $record->setMorphType($this->morphType)
->setMorphClass($this->morphClass)
: $record;
});
}

Expand Down

0 comments on commit 110b129

Please sign in to comment.