diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index a2b9b07c5b02..3585c5811b2b 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -3749,12 +3749,18 @@ public function updateFrom(array $values) * Insert or update a record matching the attributes, and fill it with values. * * @param array $attributes - * @param array $values + * @param array|callable $values * @return bool */ - public function updateOrInsert(array $attributes, array $values = []) + public function updateOrInsert(array $attributes, array|callable $values = []) { - if (! $this->where($attributes)->exists()) { + $exists = $this->where($attributes)->exists(); + + if ($values instanceof Closure) { + $values = $values($exists); + } + + if (! $exists) { return $this->insert(array_merge($attributes, $values)); }