From 1f0e2985efd5a04babaf7fd6976c6909e017eb54 Mon Sep 17 00:00:00 2001 From: mpyw Date: Sat, 26 Aug 2023 00:33:34 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Apply=20`useWritePdo()`?= =?UTF-8?q?=20to=20all=20`createOrFirst`=20impls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Illuminate/Database/Eloquent/Builder.php | 2 +- src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 2e17922c5353..7e4b2725bd2b 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -582,7 +582,7 @@ public function createOrFirst(array $attributes = [], array $values = []) try { return $this->withSavepointIfNeeded(fn () => $this->create(array_merge($attributes, $values))); } catch (UniqueConstraintViolationException $exception) { - return $this->where($attributes)->first(); + return $this->useWritePdo()->where($attributes)->first(); } } diff --git a/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php b/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php index 4a443ddece10..2e1078a609aa 100755 --- a/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php +++ b/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php @@ -653,7 +653,7 @@ public function createOrFirst(array $attributes = [], array $values = [], array $this->getQuery()->withSavepointIfNeeded(fn () => $this->attach($instance, $joining, $touch)); }); } catch (UniqueConstraintViolationException $exception) { - return (clone $this)->where($attributes)->first(); + return (clone $this)->useWritePdo()->where($attributes)->first(); } }