From 3aa95bec5b7e7cbf9d43b208e9dc1460895b9062 Mon Sep 17 00:00:00 2001
From: Rea Rustagi <85902999+rustagir@users.noreply.github.com>
Date: Thu, 3 Apr 2025 15:28:18 -0400
Subject: [PATCH 1/2] DOCSP-48956: replace tutorial link (#3333)
---
docs/quick-start.txt | 5 -----
docs/quick-start/next-steps.txt | 10 +++++++++-
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/docs/quick-start.txt b/docs/quick-start.txt
index 83b0c3937..ebfcb7348 100644
--- a/docs/quick-start.txt
+++ b/docs/quick-start.txt
@@ -41,11 +41,6 @@ read and write operations on the data.
`How to Build a Laravel + MongoDB Back End Service `__
MongoDB Developer Center tutorial.
- You can learn how to set up a local Laravel development environment
- and perform CRUD operations by viewing the
- :mdbu-course:`Getting Started with Laravel and MongoDB `
- MongoDB University Learning Byte.
-
If you prefer to connect to MongoDB by using the {+php-library+} without
Laravel, see `Connect to MongoDB `__
in the {+php-library+} documentation.
diff --git a/docs/quick-start/next-steps.txt b/docs/quick-start/next-steps.txt
index 1a7f45c6e..2853777fb 100644
--- a/docs/quick-start/next-steps.txt
+++ b/docs/quick-start/next-steps.txt
@@ -21,6 +21,15 @@ You can download the web application project by cloning the
`laravel-quickstart `__
GitHub repository.
+.. tip:: Build a Full Stack Application
+
+ Learn how to build a full stack application that uses {+odm-long+} by
+ following along with the `Full Stack Instagram Clone with Laravel and
+ MongoDB `__ tutorial on YouTube.
+
+Further Learning
+----------------
+
Learn more about {+odm-long+} features from the following resources:
- :ref:`laravel-fundamentals-connection`: learn how to configure your MongoDB
@@ -34,4 +43,3 @@ Learn more about {+odm-long+} features from the following resources:
- :ref:`laravel-query-builder`: use the query builder to specify MongoDB
queries and aggregations.
-
From b5e2132a1d13d32fdac881077420febf5b74e152 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?=
Date: Tue, 8 Apr 2025 16:41:50 +0200
Subject: [PATCH 2/2] PHPORM-311 Fix Update of numeric field name (#3336)
* PHPORM-311 Fix Update of numeric field name
* Use array_replace where keys must be preserved
---
src/Eloquent/Builder.php | 8 ++++----
src/Eloquent/DocumentModel.php | 4 ++--
src/Query/Builder.php | 7 ++++---
src/Relations/BelongsToMany.php | 4 ++--
src/Relations/MorphToMany.php | 4 ++--
src/Scout/ScoutEngine.php | 4 ++--
tests/Ticket/GH3335Test.php | 33 +++++++++++++++++++++++++++++++++
7 files changed, 49 insertions(+), 15 deletions(-)
create mode 100644 tests/Ticket/GH3335Test.php
diff --git a/src/Eloquent/Builder.php b/src/Eloquent/Builder.php
index f85570575..aabc526f7 100644
--- a/src/Eloquent/Builder.php
+++ b/src/Eloquent/Builder.php
@@ -18,7 +18,7 @@
use MongoDB\Model\BSONDocument;
use function array_key_exists;
-use function array_merge;
+use function array_replace;
use function collect;
use function is_array;
use function is_object;
@@ -270,7 +270,7 @@ public function firstOrCreate(array $attributes = [], array $values = [])
// createOrFirst is not supported in transaction.
if ($this->getConnection()->getSession()?->isInTransaction()) {
- return $this->create(array_merge($attributes, $values));
+ return $this->create(array_replace($attributes, $values));
}
return $this->createOrFirst($attributes, $values);
@@ -284,7 +284,7 @@ public function createOrFirst(array $attributes = [], array $values = [])
}
try {
- return $this->create(array_merge($attributes, $values));
+ return $this->create(array_replace($attributes, $values));
} catch (BulkWriteException $e) {
if ($e->getCode() === self::DUPLICATE_KEY_ERROR) {
return $this->where($attributes)->first() ?? throw $e;
@@ -309,7 +309,7 @@ protected function addUpdatedAtColumn(array $values)
}
$column = $this->model->getUpdatedAtColumn();
- $values = array_merge(
+ $values = array_replace(
[$column => $this->model->freshTimestampString()],
$values,
);
diff --git a/src/Eloquent/DocumentModel.php b/src/Eloquent/DocumentModel.php
index 930ed6286..d39a12401 100644
--- a/src/Eloquent/DocumentModel.php
+++ b/src/Eloquent/DocumentModel.php
@@ -30,7 +30,7 @@
use function array_key_exists;
use function array_keys;
-use function array_merge;
+use function array_replace;
use function array_unique;
use function array_values;
use function class_basename;
@@ -192,7 +192,7 @@ protected function transformModelValue($key, $value)
// to a Carbon or CarbonImmutable instance.
// @see Model::setAttribute()
if ($this->hasCast($key) && $value instanceof CarbonInterface) {
- $value->settings(array_merge($value->getSettings(), ['toStringFormat' => $this->getDateFormat()]));
+ $value->settings(array_replace($value->getSettings(), ['toStringFormat' => $this->getDateFormat()]));
// "date" cast resets the time to 00:00:00.
$castType = $this->getCasts()[$key];
diff --git a/src/Query/Builder.php b/src/Query/Builder.php
index 5c873380b..07a3483b0 100644
--- a/src/Query/Builder.php
+++ b/src/Query/Builder.php
@@ -40,6 +40,7 @@
use function array_key_exists;
use function array_map;
use function array_merge;
+use function array_replace;
use function array_values;
use function assert;
use function blank;
@@ -426,7 +427,7 @@ public function toMql(): array
// Add custom query options
if (count($this->options)) {
- $options = array_merge($options, $this->options);
+ $options = array_replace($options, $this->options);
}
$options = $this->inheritConnectionOptions($options);
@@ -450,7 +451,7 @@ public function toMql(): array
// Add custom projections.
if ($this->projections) {
- $projection = array_merge($projection, $this->projections);
+ $projection = array_replace($projection, $this->projections);
}
$options = [];
@@ -484,7 +485,7 @@ public function toMql(): array
// Add custom query options
if (count($this->options)) {
- $options = array_merge($options, $this->options);
+ $options = array_replace($options, $this->options);
}
$options = $this->inheritConnectionOptions($options);
diff --git a/src/Relations/BelongsToMany.php b/src/Relations/BelongsToMany.php
index a150fccf7..042ec22ce 100644
--- a/src/Relations/BelongsToMany.php
+++ b/src/Relations/BelongsToMany.php
@@ -14,7 +14,7 @@
use function array_diff;
use function array_keys;
use function array_map;
-use function array_merge;
+use function array_replace;
use function array_values;
use function assert;
use function count;
@@ -164,7 +164,7 @@ public function sync($ids, $detaching = true)
// Now we are finally ready to attach the new records. Note that we'll disable
// touching until after the entire operation is complete so we don't fire a
// ton of touch operations until we are totally done syncing the records.
- $changes = array_merge(
+ $changes = array_replace(
$changes,
$this->attachNew($records, $current, false),
);
diff --git a/src/Relations/MorphToMany.php b/src/Relations/MorphToMany.php
index 929738360..a1514d235 100644
--- a/src/Relations/MorphToMany.php
+++ b/src/Relations/MorphToMany.php
@@ -15,8 +15,8 @@
use function array_key_exists;
use function array_keys;
use function array_map;
-use function array_merge;
use function array_reduce;
+use function array_replace;
use function array_values;
use function collect;
use function count;
@@ -190,7 +190,7 @@ public function sync($ids, $detaching = true)
// Now we are finally ready to attach the new records. Note that we'll disable
// touching until after the entire operation is complete so we don't fire a
// ton of touch operations until we are totally done syncing the records.
- $changes = array_merge(
+ $changes = array_replace(
$changes,
$this->attachNew($records, $current, false),
);
diff --git a/src/Scout/ScoutEngine.php b/src/Scout/ScoutEngine.php
index dc70a39e2..9455608bb 100644
--- a/src/Scout/ScoutEngine.php
+++ b/src/Scout/ScoutEngine.php
@@ -29,7 +29,7 @@
use function array_column;
use function array_flip;
use function array_map;
-use function array_merge;
+use function array_replace;
use function assert;
use function call_user_func;
use function class_uses_recursive;
@@ -117,7 +117,7 @@ public function update($models)
unset($searchableData['_id']);
- $searchableData = array_merge($searchableData, $model->scoutMetadata());
+ $searchableData = array_replace($searchableData, $model->scoutMetadata());
/** Convert the __soft_deleted set by {@see Searchable::pushSoftDeleteMetadata()}
* into a boolean for efficient storage and indexing. */
diff --git a/tests/Ticket/GH3335Test.php b/tests/Ticket/GH3335Test.php
new file mode 100644
index 000000000..f37782a4b
--- /dev/null
+++ b/tests/Ticket/GH3335Test.php
@@ -0,0 +1,33 @@
+id = 'foo';
+ $model->save();
+
+ $model = Location::find('foo');
+ $model->{'38'} = 'PHP';
+ $model->save();
+
+ $model = Location::find('foo');
+ self::assertSame('PHP', $model->{'38'});
+ }
+}