Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 82d9993

Browse files
Merge 4.2 into 4.3 (#2933)
2 parents f93aaa7 + adf5566 commit 82d9993

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

‎docs/query-builder.txt‎

Lines changed: 4 additions & 1 deletion
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‎

Lines changed: 23 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /