From 42ceb5147e7f0ab88fd87313fcb6e72b82669676 Mon Sep 17 00:00:00 2001 From: rustagir Date: Wed, 11 Jun 2025 16:14:40 -0400 Subject: [PATCH 1/4] DOCSP-50607: multiply/divide QB methods --- .../query-builder/QueryBuilderTest.php | 36 ++++++++++++++----- docs/query-builder.txt | 36 +++++++++++++++++++ 2 files changed, 64 insertions(+), 8 deletions(-) diff --git a/docs/includes/query-builder/QueryBuilderTest.php b/docs/includes/query-builder/QueryBuilderTest.php index 3f7ea2274..0e280b845 100644 --- a/docs/includes/query-builder/QueryBuilderTest.php +++ b/docs/includes/query-builder/QueryBuilderTest.php @@ -213,10 +213,10 @@ public function testGroupBy(): void { // begin query groupBy $result = DB::table('movies') - ->where('rated', 'G') - ->groupBy('runtime') - ->orderBy('runtime', 'asc') - ->get(['title']); + ->where('rated', 'G') + ->groupBy('runtime') + ->orderBy('runtime', 'asc') + ->get(['title']); // end query groupBy $this->assertInstanceOf(\Illuminate\Support\Collection::class, $result); @@ -420,10 +420,10 @@ public function testWhereRaw(): void // begin query raw $result = DB::table('movies') ->whereRaw([ - 'imdb.votes' => ['$gte' => 1000 ], + 'imdb.votes' => ['$gte' => 1000], '$or' => [ ['imdb.rating' => ['$gt' => 7]], - ['directors' => ['$in' => [ 'Yasujiro Ozu', 'Sofia Coppola', 'Federico Fellini' ]]], + ['directors' => ['$in' => ['Yasujiro Ozu', 'Sofia Coppola', 'Federico Fellini']]], ], ])->get(); // end query raw @@ -470,7 +470,7 @@ public function testNear(): void { $this->importTheaters(); - // begin query near + // begin query near $results = DB::table('theaters') ->where('location.geo', 'near', [ '$geometry' => [ @@ -588,7 +588,7 @@ public function testUpdateUpsert(): void [ 'plot' => 'An autobiographical movie', 'year' => 1998, - 'writers' => [ 'Will Hunting' ], + 'writers' => ['Will Hunting'], ], ['upsert' => true], ); @@ -597,6 +597,26 @@ public function testUpdateUpsert(): void $this->assertIsInt($result); } + public function testMultiplyDivide(): void + { + // begin multiply divide + $result = DB::table('movies') + ->where('year', 2001) + ->multiply('imdb.votes', 5) + ->divide('runtime', 2); + // end multiply divide + + $this->assertIsInt($result); + + // begin multiply with set + $result = DB::table('movies') + ->where('year', 1958) + ->multiply('runtime', 1.5, ['note' => 'Adds recovered footage & interviews.']); + // end multiply with set + + $this->assertIsInt($result); + } + public function testIncrement(): void { // begin increment diff --git a/docs/query-builder.txt b/docs/query-builder.txt index a73d5e791..5f570ea67 100644 --- a/docs/query-builder.txt +++ b/docs/query-builder.txt @@ -1169,6 +1169,7 @@ This section includes query builder examples that show how to use the following MongoDB-specific write operations: - :ref:`Upsert a document ` +- :ref:`Multiply and divide values ` - :ref:`Increment a numerical value ` - :ref:`Decrement a numerical value ` - :ref:`Add an array element ` @@ -1252,6 +1253,41 @@ and the ``title`` field and value specified in the ``where()`` query operation: The ``update()`` query builder method returns the number of documents that the operation updated or inserted. +.. _laravel-mongodb-query-builder-mul-div: + +Multiply and Divide Numerical Values Example +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can perform multiplication and division operations on numerical +values by using the ``multiply()`` and ``divide()`` query builder +methods. + +The following example shows how to use the ``multiply()`` and +``divide()`` query builder methods to manipulate the values of the +``imdb.votes`` and ``runtime`` fields: + +.. literalinclude:: /includes/query-builder/QueryBuilderTest.php + :language: php + :dedent: + :start-after: begin multiply divide + :end-before: end multiply divide + +.. tip:: update() Method + + You can perform the same operations by using the ``update()`` + method and passing an update document that includes the :manual:`$mul + ` operator. To learn more about + ``update()``, see the :ref:`laravel-fundamentals-write-modify` guide. + +You can optionally pass an array parameter to perform a ``$set`` update +in the same operation, as shown in the following example: + +.. literalinclude:: /includes/query-builder/QueryBuilderTest.php + :language: php + :dedent: + :start-after: begin multiply with set + :end-before: end multiply with set + .. _laravel-mongodb-query-builder-increment: Increment a Numerical Value Example From 3f3bc48826c4c3d935c5bde4c4d0dfd7fe1e91b0 Mon Sep 17 00:00:00 2001 From: rustagir Date: Wed, 11 Jun 2025 16:19:23 -0400 Subject: [PATCH 2/4] separate mul & div examples --- docs/includes/query-builder/QueryBuilderTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/includes/query-builder/QueryBuilderTest.php b/docs/includes/query-builder/QueryBuilderTest.php index 0e280b845..e9e21fa79 100644 --- a/docs/includes/query-builder/QueryBuilderTest.php +++ b/docs/includes/query-builder/QueryBuilderTest.php @@ -602,7 +602,10 @@ public function testMultiplyDivide(): void // begin multiply divide $result = DB::table('movies') ->where('year', 2001) - ->multiply('imdb.votes', 5) + ->multiply('imdb.votes', 5); + + $result = DB::table('movies') + ->where('year', 2001) ->divide('runtime', 2); // end multiply divide From 5fb5fcf5cfd5fbdea24d9a46bc5f6d90e3c56573 Mon Sep 17 00:00:00 2001 From: rustagir Date: Wed, 11 Jun 2025 16:22:44 -0400 Subject: [PATCH 3/4] add versioning --- docs/eloquent-models/schema-builder.txt | 6 +++--- docs/query-builder.txt | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/eloquent-models/schema-builder.txt b/docs/eloquent-models/schema-builder.txt index e9c1dff17..a3e1df913 100644 --- a/docs/eloquent-models/schema-builder.txt +++ b/docs/eloquent-models/schema-builder.txt @@ -117,9 +117,9 @@ in the Laravel documentation. Implement Schema Validation --------------------------- -You can use the ``jsonSchema()`` method to implement :manual:`schema -validation ` when using the following schema -builder methods: +Starting in {+odm-short+} v5.5, you can use the ``jsonSchema()`` method +to implement :manual:`schema validation ` when +using the following schema builder methods: - ``Schema::create()``: When creating a new collection - ``Schema::table()``: When updating collection properties diff --git a/docs/query-builder.txt b/docs/query-builder.txt index 5f570ea67..f4398822e 100644 --- a/docs/query-builder.txt +++ b/docs/query-builder.txt @@ -1258,9 +1258,9 @@ operation updated or inserted. Multiply and Divide Numerical Values Example ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -You can perform multiplication and division operations on numerical -values by using the ``multiply()`` and ``divide()`` query builder -methods. +Starting in {+odm-short+} v5.5, you can perform multiplication and +division operations on numerical values by using the ``multiply()`` and +``divide()`` query builder methods. The following example shows how to use the ``multiply()`` and ``divide()`` query builder methods to manipulate the values of the From 0cff62b4bf9d94fe4462c4ed0a2a4ef02923e87d Mon Sep 17 00:00:00 2001 From: rustagir Date: Wed, 11 Jun 2025 16:24:55 -0400 Subject: [PATCH 4/4] wip --- docs/includes/query-builder/QueryBuilderTest.php | 2 +- docs/query-builder.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/includes/query-builder/QueryBuilderTest.php b/docs/includes/query-builder/QueryBuilderTest.php index e9e21fa79..a90f1685f 100644 --- a/docs/includes/query-builder/QueryBuilderTest.php +++ b/docs/includes/query-builder/QueryBuilderTest.php @@ -614,7 +614,7 @@ public function testMultiplyDivide(): void // begin multiply with set $result = DB::table('movies') ->where('year', 1958) - ->multiply('runtime', 1.5, ['note' => 'Adds recovered footage & interviews.']); + ->multiply('runtime', 1.5, ['note' => 'Adds recovered footage.']); // end multiply with set $this->assertIsInt($result); diff --git a/docs/query-builder.txt b/docs/query-builder.txt index f4398822e..2358ed7d5 100644 --- a/docs/query-builder.txt +++ b/docs/query-builder.txt @@ -1263,7 +1263,7 @@ division operations on numerical values by using the ``multiply()`` and ``divide()`` query builder methods. The following example shows how to use the ``multiply()`` and -``divide()`` query builder methods to manipulate the values of the +``divide()`` methods to manipulate the values of the ``imdb.votes`` and ``runtime`` fields: .. literalinclude:: /includes/query-builder/QueryBuilderTest.php