Skip to content

Commit f498f97

Browse files
committed
wip
1 parent 7cb0b12 commit f498f97

File tree

7 files changed

+288
-123
lines changed

7 files changed

+288
-123
lines changed

Diff for: docs/includes/usage-examples/FindOneTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ public function testFindOne(): void
3232
// end-eloquent-find-one
3333

3434
$this->assertInstanceOf(Movie::class, $movie);
35-
$this->expectOutputRegex('/^{"_id":"[a-z0-9]{24}","title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\]}$/');
35+
$this->assertSame($movie->title, 'The Shawshank Redemption');
3636

3737
// begin-qb-find-one
3838
$movie = DB::table('movies')
3939
->where('directors', 'Rob Reiner')
4040
->orderBy('_id')
4141
->first();
4242

43-
echo $movie[0]->toJson();
43+
echo print_r($movie);
4444
// end-qb-find-one
4545
}
4646
}

Diff for: docs/includes/usage-examples/InsertOneTest.php

+15-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace App\Http\Controllers;
66

77
use App\Models\Movie;
8+
use Illuminate\Support\Facades\DB;
89
use MongoDB\Laravel\Tests\TestCase;
910

1011
class InsertOneTest extends TestCase
@@ -19,17 +20,28 @@ public function testInsertOne(): void
1920

2021
Movie::truncate();
2122

22-
// begin-insert-one
23+
// begin-eloquent-insert-one
2324
$movie = Movie::create([
2425
'title' => 'Marriage Story',
2526
'year' => 2019,
2627
'runtime' => 136,
2728
]);
2829

2930
echo $movie->toJson();
30-
// end-insert-one
31+
// end-eloquent-insert-one
32+
33+
// begin-qb-insert-one
34+
$success = DB::table('movies')
35+
->insert([
36+
'title' => 'Marriage Story',
37+
'year' => 2019,
38+
'runtime' => 136,
39+
]);
40+
41+
echo 'Insert operation success: ' . ($success ? 'yes' : 'no');
42+
// end-qb-insert-one
3143

3244
$this->assertInstanceOf(Movie::class, $movie);
33-
$this->expectOutputRegex('/^{"title":"Marriage Story","year":2019,"runtime":136,"updated_at":".{27}","created_at":".{27}","_id":"[a-z0-9]{24}"}$/');
45+
$this->assertSame($movie->title, 'Marriage Story');
3446
}
3547
}

Diff for: docs/includes/usage-examples/UpdateManyTest.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace App\Http\Controllers;
66

77
use App\Models\Movie;
8+
use Illuminate\Support\Facades\DB;
89
use MongoDB\Laravel\Tests\TestCase;
910

1011
class UpdateManyTest extends TestCase
@@ -35,14 +36,23 @@ public function testUpdateMany(): void
3536
],
3637
]);
3738

38-
// begin-update-many
39+
// begin-eloquent-update-many
3940
$updates = Movie::where('imdb.rating', '>', 9.0)
4041
->update(['acclaimed' => true]);
4142

4243
echo 'Updated documents: ' . $updates;
43-
// end-update-many
44+
// end-eloquent-update-many
4445

4546
$this->assertEquals(2, $updates);
46-
$this->expectOutputString('Updated documents: 2');
47+
48+
// begin-qb-update-many
49+
$updates = DB::table('movies')
50+
->where('imdb.rating', '>', 9.0)
51+
->update(['acclaimed' => true]);
52+
53+
echo 'Updated documents: ' . $updates;
54+
// end-qb-update-many
55+
56+
$this->expectOutputString('Updated documents: 2Updated documents: 0');
4757
}
4858
}

Diff for: docs/includes/usage-examples/UpdateOneTest.php

+20-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace App\Http\Controllers;
66

77
use App\Models\Movie;
8+
use Illuminate\Support\Facades\DB;
89
use MongoDB\Laravel\Tests\TestCase;
910

1011
class UpdateOneTest extends TestCase
@@ -28,7 +29,7 @@ public function testUpdateOne(): void
2829
],
2930
]);
3031

31-
// begin-update-one
32+
// begin-eloquent-update-one
3233
$updates = Movie::where('title', 'Carol')
3334
->orderBy('_id')
3435
->first()
@@ -40,9 +41,25 @@ public function testUpdateOne(): void
4041
]);
4142

4243
echo 'Updated documents: ' . $updates;
43-
// end-update-one
44+
// end-eloquent-update-one
4445

4546
$this->assertTrue($updates);
46-
$this->expectOutputString('Updated documents: 1');
47+
48+
// begin-qb-update-one
49+
$updates = DB::table('movies')
50+
->where('title', 'Carol')
51+
->orderBy('_id')
52+
->first()
53+
->update([
54+
'imdb' => [
55+
'rating' => 7.3,
56+
'votes' => 142000,
57+
],
58+
]);
59+
60+
echo 'Updated documents: ' . $updates;
61+
// end-qb-update-one
62+
63+
$this->expectOutputString('Updated documents: 1Updated documents: 0');
4764
}
4865
}

Diff for: docs/usage-examples/insertOne.txt

+80-42
Original file line numberDiff line numberDiff line change
@@ -23,50 +23,88 @@ an Eloquent model or query builder.
2323
To insert a document, pass the data you need to insert as a document containing
2424
the fields and values to the ``create()`` method.
2525

26-
Example
27-
-------
28-
29-
This usage example performs the following actions:
30-
31-
- Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the
32-
``sample_mflix`` database
33-
- Inserts a document into the ``movies`` collection
34-
35-
The example calls the ``create()`` method to insert a document that contains the following
36-
information:
37-
38-
- ``title`` value of ``"Marriage Story"``
39-
- ``year`` value of ``2019``
40-
- ``runtime`` value of ``136``
41-
42-
.. io-code-block::
43-
:copyable: true
26+
.. tip::
4427

45-
.. input:: ../includes/usage-examples/InsertOneTest.php
46-
:start-after: begin-insert-one
47-
:end-before: end-insert-one
48-
:language: php
49-
:dedent:
28+
You can also use the ``save()`` or ``insert()`` methods to insert a
29+
document into a collection. To learn more about insert operations,
30+
see the :ref:`laravel-fundamentals-insert-documents` section of the
31+
Write Operations guide.
5032

51-
.. output::
52-
:language: json
53-
:visible: false
33+
Example
34+
-------
5435

55-
{
56-
"title": "Marriage Story",
57-
"year": 2019,
58-
"runtime": 136,
59-
"updated_at": "...",
60-
"created_at": "...",
61-
"_id": "..."
62-
}
36+
Select from the following :guilabel:`Eloquent` and :guilabel:`Query
37+
Builder` tabs to view usage examples for the same operation that use
38+
each corresponding query syntax:
39+
40+
.. tabs::
41+
42+
.. tab:: Eloquent
43+
:tabid: eloquent-model-count
44+
45+
This example performs the following actions:
46+
47+
- Uses the ``Movie`` Eloquent model to represent the ``movies``
48+
collection in the ``sample_mflix`` database
49+
- Inserts a document into the ``movies`` collection
50+
51+
The example calls the ``create()`` method to insert a document
52+
that contains the following fields and values:
53+
54+
- ``title`` value of ``"Marriage Story"``
55+
- ``year`` value of ``2019``
56+
- ``runtime`` value of ``136``
57+
58+
.. io-code-block::
59+
:copyable: true
60+
61+
.. input:: ../includes/usage-examples/InsertOneTest.php
62+
:start-after: begin-eloquent-insert-one
63+
:end-before: end-eloquent-insert-one
64+
:language: php
65+
:dedent:
66+
67+
.. output::
68+
:language: console
69+
:visible: false
70+
71+
{
72+
"title": "Marriage Story",
73+
"year": 2019,
74+
"runtime": 136,
75+
"updated_at": "...",
76+
"created_at": "...",
77+
"_id": "..."
78+
}
79+
80+
.. tab:: Query Builder
81+
:tabid: query-builder-count
82+
83+
This example performs the following actions:
84+
85+
- Accesses the ``movies`` collection by calling the ``table()``
86+
method from the ``DB`` facade
87+
- Inserts a document into the ``movies`` collection
88+
89+
The example calls the ``create()`` method to insert a document
90+
that contains the following fields and values:
91+
92+
- ``title`` value of ``"Marriage Story"``
93+
- ``year`` value of ``2019``
94+
- ``runtime`` value of ``136``
95+
96+
.. io-code-block::
97+
98+
.. input:: ../includes/usage-examples/InsertOneTest.php
99+
:start-after: begin-qb-insert-one
100+
:end-before: end-qb-insert-one
101+
:language: php
102+
:dedent:
103+
104+
.. output::
105+
:language: console
106+
:visible: false
107+
108+
Insert operation success: yes
63109

64110
.. include:: /includes/usage-examples/fact-edit-laravel-app.rst
65-
66-
.. tip::
67-
68-
You can also use the ``save()`` or ``insert()`` methods to insert a document into a collection.
69-
To learn more about insert operations, see the :ref:`laravel-fundamentals-insert-documents` section
70-
of the Write Operations guide.
71-
72-

Diff for: docs/usage-examples/updateMany.txt

+77-35
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,85 @@ Pass a query filter to the ``where()`` method to retrieve documents that meet a
2424
set of criteria. Then, update the matching documents by passing your intended
2525
document changes to the ``update()`` method.
2626

27-
Example
28-
-------
29-
30-
This usage example performs the following actions:
31-
32-
- Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the
33-
``sample_mflix`` database
34-
- Updates documents from the ``movies`` collection that match a query filter
35-
- Prints the number of updated documents
36-
37-
The example calls the following methods on the ``Movie`` model:
38-
39-
- ``where()``: matches documents in which the value of the ``imdb.rating`` nested field
40-
is greater than ``9.0``.
41-
- ``update()``: updates the matching documents by adding an ``acclaimed`` field and setting
42-
its value to ``true``. This method returns the number of documents that were successfully
43-
updated.
44-
45-
.. io-code-block::
46-
:copyable: true
47-
48-
.. input:: ../includes/usage-examples/UpdateManyTest.php
49-
:start-after: begin-update-many
50-
:end-before: end-update-many
51-
:language: php
52-
:dedent:
53-
54-
.. output::
55-
:language: console
56-
:visible: false
57-
58-
Updated documents: 20
59-
60-
.. include:: /includes/usage-examples/fact-edit-laravel-app.rst
61-
6227
.. tip::
6328

6429
To learn more about updating data with the {+odm-short+}, see the :ref:`laravel-fundamentals-modify-documents`
6530
section of the Write Operations guide.
6631

32+
Example
33+
-------
34+
35+
Select from the following :guilabel:`Eloquent` and :guilabel:`Query
36+
Builder` tabs to view usage examples for the same operation that use
37+
each corresponding query syntax:
38+
39+
.. tabs::
40+
41+
.. tab:: Eloquent
42+
:tabid: eloquent-model-count
43+
44+
This example performs the following actions:
45+
46+
- Uses the ``Movie`` Eloquent model to represent the ``movies``
47+
collection in the ``sample_mflix`` database
48+
- Updates documents from the ``movies`` collection that match a
49+
query filter
50+
- Prints the number of updated documents
51+
52+
The example calls the following methods on the ``Movie`` model:
53+
54+
- ``where()``: Matches documents in which the value of the
55+
``imdb.rating`` nested field is greater than ``9.0``
56+
- ``update()``: Updates the matching documents by adding an
57+
``acclaimed`` field and setting its value to ``true``, then
58+
returns the number of updated documents
59+
60+
.. io-code-block::
61+
:copyable: true
62+
63+
.. input:: ../includes/usage-examples/UpdateManyTest.php
64+
:start-after: begin-eloquent-update-many
65+
:end-before: end-eloquent-update-many
66+
:language: php
67+
:dedent:
68+
69+
.. output::
70+
:language: console
71+
:visible: false
72+
73+
Updated documents: 20
74+
75+
.. tab:: Query Builder
76+
:tabid: query-builder-count
77+
78+
This example performs the following actions:
79+
80+
- Accesses the ``movies`` collection by calling the ``table()``
81+
method from the ``DB`` facade
82+
- Updates documents from the ``movies`` collection that match a
83+
query filter
84+
- Prints the number of updated documents
85+
86+
The example calls the following query builder methods:
87+
88+
- ``where()``: Matches documents in which the value of the
89+
``imdb.rating`` nested field is greater than ``9.0``
90+
- ``update()``: Updates the matching documents by adding an
91+
``acclaimed`` field and setting its value to ``true``, then
92+
returns the number of updated documents
93+
94+
.. io-code-block::
95+
96+
.. input:: ../includes/usage-examples/UpdateManyTest.php
97+
:start-after: begin-qb-update-many
98+
:end-before: end-qb-update-many
99+
:language: php
100+
:dedent:
101+
102+
.. output::
103+
:language: console
104+
:visible: false
105+
106+
Updated documents: 20
107+
108+
.. include:: /includes/usage-examples/fact-edit-laravel-app.rst

0 commit comments

Comments
 (0)