Skip to content

Commit 2c19a64

Browse files
committed
fixes - RM and moved a section
1 parent 17ab049 commit 2c19a64

File tree

3 files changed

+74
-79
lines changed

3 files changed

+74
-79
lines changed

docs/fundamentals/read-operations.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@ from a collection:
5050
To view a runnable example that finds one document, see the
5151
:ref:`laravel-find-one-usage` usage example.
5252

53-
To learn more about retrieving documents, see the
54-
:ref:`laravel-fundamentals-read-retrieve` guide.
55-
56-
To learn more about the ``first()`` method, see the
57-
:ref:`laravel-fundamentals-read-retrieve` guide.
53+
To learn more about retrieving documents and the ``first()`` method, see
54+
the :ref:`laravel-fundamentals-read-retrieve` guide.
5855

5956
Find Multiple
6057
-------------

docs/fundamentals/read-operations/modify-results.txt

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ The following sections demonstrate how to modify the behavior of the
3232
to skip and the ``take()`` method to set the total number of documents to return
3333
- :ref:`laravel-sort` uses the ``orderBy()`` method to return query
3434
results in a specified order based on field values
35-
- :ref:`laravel-retrieve-one` uses the ``first()`` method to return the first document
36-
that matches the query filter
3735

3836
To learn more about Eloquent models in the {+odm-short+}, see the
3937
:ref:`laravel-eloquent-models` section.
@@ -216,77 +214,6 @@ This example queries for documents in which the value of the ``countries`` field
216214
- `Ordering, Grouping, Limit, and Offset <https://laravel.com/docs/queries#ordering-grouping-limit-and-offset>`__
217215
in the Laravel documentation
218216

219-
.. _laravel-retrieve-one:
220-
221-
Return the First Result
222-
-----------------------
223-
224-
To retrieve the first document that matches a set of criteria, use the ``where()`` method
225-
followed by the ``first()`` method.
226-
227-
Chain the ``orderBy()`` method to ``first()`` to get consistent results when you query on a unique
228-
value. If you omit the ``orderBy()`` method, MongoDB returns the matching documents according to
229-
the documents' natural order, or as they appear in the collection.
230-
231-
This example queries for documents in which the value of the ``runtime`` field is
232-
``30`` and returns the first matching document according to the value of the ``_id``
233-
field.
234-
235-
.. tabs::
236-
237-
.. tab:: Query Syntax
238-
:tabid: query-syntax
239-
240-
Use the following syntax to specify the query:
241-
242-
.. literalinclude:: /includes/fundamentals/read-operations/ReadOperationsTest.php
243-
:language: php
244-
:dedent:
245-
:start-after: start-first
246-
:end-before: end-first
247-
248-
.. tab:: Controller Method
249-
:tabid: controller
250-
251-
To see the query results in the ``browse_movies`` view, edit the ``show()`` function
252-
in the ``MovieController.php`` file to resemble the following code:
253-
254-
.. io-code-block::
255-
:copyable: true
256-
257-
.. input::
258-
:language: php
259-
260-
class MovieController
261-
{
262-
public function show()
263-
{
264-
$movie = Movie::where('runtime', 30)
265-
->orderBy('_id')
266-
->first();
267-
268-
return view('browse_movies', [
269-
'movies' => $movie
270-
]);
271-
}
272-
}
273-
274-
.. output::
275-
:language: none
276-
:visible: false
277-
278-
Title: Statues also Die
279-
Year: 1953
280-
Runtime: 30
281-
IMDB Rating: 7.6
282-
IMDB Votes: 620
283-
Plot: A documentary of black art.
284-
285-
.. tip::
286-
287-
To learn more about the ``orderBy()`` method, see the
288-
:ref:`laravel-sort` section of this guide.
289-
290217
Additional Information
291218
----------------------
292219

docs/fundamentals/read-operations/retrieve.txt

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ filter to the method.
4949
The ``where()`` method retrieves all matching documents. To retrieve
5050
the first matching document, you can chain the ``first()`` method. To
5151
learn more and view an example, see the :ref:`laravel-retrieve-one`
52-
section of the Modify Query Results guide.
52+
section of this guide.
5353

5454
A query filter specifies field value requirements and instructs the find
5555
operation to return only documents that meet these requirements.
@@ -191,6 +191,77 @@ To learn how to query array fields by using the Laravel query builder instead of
191191
Eloquent ORM, see the :ref:`laravel-query-builder-elemMatch` section in
192192
the Query Builder guide.
193193

194+
.. _laravel-retrieve-one:
195+
196+
Retrieve the First Result
197+
-------------------------
198+
199+
To retrieve the first document that matches a set of criteria, use the ``where()`` method
200+
followed by the ``first()`` method.
201+
202+
Chain the ``orderBy()`` method to ``first()`` to get consistent results when you query on a unique
203+
value. If you omit the ``orderBy()`` method, MongoDB returns the matching documents according to
204+
the documents' natural order, or as they appear in the collection.
205+
206+
This example queries for documents in which the value of the ``runtime`` field is
207+
``30`` and returns the first matching document according to the value of the ``_id``
208+
field.
209+
210+
.. tabs::
211+
212+
.. tab:: Query Syntax
213+
:tabid: query-syntax
214+
215+
Use the following syntax to specify the query:
216+
217+
.. literalinclude:: /includes/fundamentals/read-operations/ReadOperationsTest.php
218+
:language: php
219+
:dedent:
220+
:start-after: start-first
221+
:end-before: end-first
222+
223+
.. tab:: Controller Method
224+
:tabid: controller
225+
226+
To see the query results in the ``browse_movies`` view, edit the ``show()`` function
227+
in the ``MovieController.php`` file to resemble the following code:
228+
229+
.. io-code-block::
230+
:copyable: true
231+
232+
.. input::
233+
:language: php
234+
235+
class MovieController
236+
{
237+
public function show()
238+
{
239+
$movie = Movie::where('runtime', 30)
240+
->orderBy('_id')
241+
->first();
242+
243+
return view('browse_movies', [
244+
'movies' => $movie
245+
]);
246+
}
247+
}
248+
249+
.. output::
250+
:language: none
251+
:visible: false
252+
253+
Title: Statues also Die
254+
Year: 1953
255+
Runtime: 30
256+
IMDB Rating: 7.6
257+
IMDB Votes: 620
258+
Plot: A documentary of black art.
259+
260+
.. tip::
261+
262+
To learn more about the ``orderBy()`` method, see the
263+
:ref:`laravel-sort` section of the Modify Query Results guide.
264+
194265
.. _laravel-retrieve-all:
195266

196267
Retrieve All Documents in a Collection

0 commit comments

Comments
 (0)