From c50f3ae40eb086f18ef98f50cfaa5bef2f1b5166 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 23 Mar 2024 21:18:12 +0000 Subject: [PATCH 1/2] Fix belongs to many touch using key instead of owner key --- src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php b/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php index c0459b4d7267..63278440e021 100755 --- a/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php +++ b/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php @@ -1191,7 +1191,8 @@ public function touch() // the related model's timestamps, to make sure these all reflect the changes // to the parent models. This will help us keep any caching synced up here. if (count($ids = $this->allRelatedIds()) > 0) { - $this->getRelated()->newQueryWithoutRelationships()->whereKey($ids)->update($columns); + $whereIn = $this->whereInMethod($this->related, $this->relatedKey); + $this->getRelated()->newQueryWithoutRelationships()->{$whereIn}($this->relatedKey, $ids)->update($columns); } } From 07978f0f3eeaea84b5b70b6f81248a9c077d9010 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 24 Mar 2024 10:03:09 -0500 Subject: [PATCH 2/2] Update BelongsToMany.php --- src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php b/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php index 63278440e021..c94643eaf05c 100755 --- a/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php +++ b/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php @@ -1192,6 +1192,7 @@ public function touch() // to the parent models. This will help us keep any caching synced up here. if (count($ids = $this->allRelatedIds()) > 0) { $whereIn = $this->whereInMethod($this->related, $this->relatedKey); + $this->getRelated()->newQueryWithoutRelationships()->{$whereIn}($this->relatedKey, $ids)->update($columns); } }