diff --git a/src/Illuminate/Database/Eloquent/Relations/MorphToMany.php b/src/Illuminate/Database/Eloquent/Relations/MorphToMany.php index 79a052af1a61..3bb7ab83b487 100644 --- a/src/Illuminate/Database/Eloquent/Relations/MorphToMany.php +++ b/src/Illuminate/Database/Eloquent/Relations/MorphToMany.php @@ -115,6 +115,19 @@ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, ); } + /** + * Get the pivot models that are currently attached. + * + * @return \Illuminate\Support\Collection + */ + protected function getCurrentlyAttachedPivots() + { + return parent::getCurrentlyAttachedPivots()->map(function ($record) { + return $record->setMorphType($this->morphType) + ->setMorphClass($this->morphClass); + }); + } + /** * Create a new query builder for the pivot table. *