From 684208b10460b49fa34354cc42f33b9b7135814f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 28 May 2020 22:10:45 -0500 Subject: [PATCH] fix bug with update existing pivot and polymorphic many to many --- .../Database/Eloquent/Relations/MorphToMany.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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. *