Skip to content

Merge 4.3 into 4.4 #2934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 23 additions & 0 deletions docs/quick-start/view-data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,29 @@ 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();

return $results->toJson();
}

.. step:: Start your Laravel application

Expand Down
Loading