Skip to content

Commit adf5566

Browse files
Merge 4.1 into 4.2 (#2932)
2 parents df75d8a + d1802d1 commit adf5566

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

docs/query-builder.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ Before You Get Started
7373
To run the code examples in this guide, complete the
7474
:ref:`Quick Start <laravel-quick-start>` tutorial to configure a web
7575
application, load sample datasets into your MongoDB deployment, and
76-
run the example code from a controller method.
76+
run the example code from a controller method. To see the expected code
77+
output as JSON documents, use the ``toJson()`` method shown in the optional
78+
:ref:`View your results as JSON documents <laravel-quick-start-json>` step
79+
of the Quick Start.
7780

7881
To perform read and write operations by using the query builder, import the
7982
``Illuminate\Support\Facades\DB`` facade and compose your query.

docs/quick-start/view-data.txt

+23
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,29 @@ View MongoDB Data
136136

137137
</body>
138138
</html>
139+
140+
.. _laravel-quick-start-json:
141+
142+
.. step:: Optionally, view your results as JSON documents
143+
144+
Rather than generating a view and editing the ``browse_movie.blade.php`` file, you can
145+
use the ``toJson()`` method to display your results in JSON format.
146+
147+
Replace the ``show()`` function with the following code to retrieve results and
148+
return them as JSON documents:
149+
150+
.. code-block:: php
151+
152+
public function show()
153+
{
154+
$results = Movie::where('runtime', '<', 60)
155+
->where('imdb.rating', '>', 8.5)
156+
->orderBy('imdb.rating', 'desc')
157+
->take(10)
158+
->get();
159+
160+
return $results->toJson();
161+
}
139162

140163
.. step:: Start your Laravel application
141164

0 commit comments

Comments
 (0)