Skip to content

Commit 80e0262

Browse files
authored
Enhancing updateOrCreate() to Use firstOrCreate() (#48160)
1 parent 24cbb80 commit 80e0262

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Illuminate/Database/Eloquent/Builder.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,10 @@ public function createOrFirst(array $attributes = [], array $values = [])
595595
*/
596596
public function updateOrCreate(array $attributes, array $values = [])
597597
{
598-
return tap($this->firstOrNew($attributes), function ($instance) use ($values) {
599-
$instance->fill($values)->save();
598+
return tap($this->firstOrCreate($attributes, $values), function ($instance) use ($values) {
599+
if (! $instance->wasRecentlyCreated) {
600+
$instance->fill($values)->save();
601+
}
600602
});
601603
}
602604

0 commit comments

Comments
 (0)