Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/query-builder.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ Before You Get Started
To run the code examples in this guide, complete the
:ref:`Quick Start <laravel-quick-start>` tutorial to configure a web
application, load sample datasets into your MongoDB deployment, and
run the example code from a controller method.
run the example code from a controller method. To see the expected code
output as JSON documents, use the ``toJson()`` method shown in the optional
:ref:`View your results as JSON documents <laravel-quick-start-json>` step
of the Quick Start.

To perform read and write operations by using the query builder, import the
``Illuminate\Support\Facades\DB`` facade and compose your query.
Expand Down
25 changes: 25 additions & 0 deletions docs/quick-start/view-data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,31 @@ View MongoDB Data

</body>
</html>

.. _laravel-quick-start-json:

.. step:: Optionally, view your results as JSON documents

Rather than generating a view and editing the ``browse_movie.blade.php`` file, you can
use the ``toJson()`` method to display your results in JSON format.

Replace the ``show()`` function with the following code to retrieve results and
return them as JSON documents:

.. code-block:: php

public function show()
{
$results = Movie::where('runtime', '<', 60)
->where('imdb.rating', '>', 8.5)
->orderBy('imdb.rating', 'desc')
->take(10)
->get();

foreach ($results as $movie) {
echo $movie->toJson() . '<br>\n';
}
}

.. step:: Start your Laravel application

Expand Down