1818use MongoDB \Model \BSONDocument ;
1919
2020use function array_key_exists ;
21- use function array_merge ;
21+ use function array_replace ;
2222use function collect ;
2323use function is_array ;
2424use function is_object ;
@@ -270,7 +270,7 @@ public function firstOrCreate(array $attributes = [], array $values = [])
270270
271271 // createOrFirst is not supported in transaction.
272272 if ($ this ->getConnection ()->getSession ()?->isInTransaction()) {
273- return $ this ->create (array_merge ($ attributes , $ values ));
273+ return $ this ->create (array_replace ($ attributes , $ values ));
274274 }
275275
276276 return $ this ->createOrFirst ($ attributes , $ values );
@@ -284,7 +284,7 @@ public function createOrFirst(array $attributes = [], array $values = [])
284284 }
285285
286286 try {
287- return $ this ->create (array_merge ($ attributes , $ values ));
287+ return $ this ->create (array_replace ($ attributes , $ values ));
288288 } catch (BulkWriteException $ e ) {
289289 if ($ e ->getCode () === self ::DUPLICATE_KEY_ERROR ) {
290290 return $ this ->where ($ attributes )->first () ?? throw $ e ;
@@ -309,7 +309,7 @@ protected function addUpdatedAtColumn(array $values)
309309 }
310310
311311 $ column = $ this ->model ->getUpdatedAtColumn ();
312- $ values = array_merge (
312+ $ values = array_replace (
313313 [$ column => $ this ->model ->freshTimestampString ()],
314314 $ values ,
315315 );
0 commit comments