File tree 2 files changed +27
-1
lines changed
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -73,7 +73,10 @@ Before You Get Started
73
73
To run the code examples in this guide, complete the
74
74
:ref:`Quick Start <laravel-quick-start>` tutorial to configure a web
75
75
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.
77
80
78
81
To perform read and write operations by using the query builder, import the
79
82
``Illuminate\Support\Facades\DB`` facade and compose your query.
Original file line number Diff line number Diff line change @@ -136,6 +136,29 @@ View MongoDB Data
136
136
137
137
</body>
138
138
</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
+ }
139
162
140
163
.. step:: Start your Laravel application
141
164
You can’t perform that action at this time.
0 commit comments