From 49355bb058ca7b2182b8c4d0085e6855665ffb09 Mon Sep 17 00:00:00 2001 From: norareidy Date: Tue, 30 Apr 2024 13:25:51 -0400 Subject: [PATCH 1/6] DOCSP-37770: Return results as JSON --- docs/quick-start/view-data.txt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/quick-start/view-data.txt b/docs/quick-start/view-data.txt index 6ce31369e..95879038c 100644 --- a/docs/quick-start/view-data.txt +++ b/docs/quick-start/view-data.txt @@ -136,6 +136,31 @@ View MongoDB Data + + .. _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() . '
\n'; + } + } .. step:: Start your Laravel application From 850c1fe661cff908b0938ef3c280a0f7bb69cdf8 Mon Sep 17 00:00:00 2001 From: norareidy Date: Tue, 30 Apr 2024 13:38:11 -0400 Subject: [PATCH 2/6] add info to query builder page --- docs/query-builder.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/query-builder.txt b/docs/query-builder.txt index 9547b1676..a47d40d0c 100644 --- a/docs/query-builder.txt +++ b/docs/query-builder.txt @@ -73,7 +73,9 @@ Before You Get Started To run the code examples in this guide, complete the :ref:`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, follow the instructions in the optional :ref:`View your results as JSON documents +` 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. @@ -84,7 +86,7 @@ Retrieve Matching Documents --------------------------- This section includes query builder examples for read operations in the -following operator categories: +following operator categoriess - :ref:`Where method ` - :ref:`Logical conditionals ` From 1a83034f7678d4cb32225642e6966e3750259cc5 Mon Sep 17 00:00:00 2001 From: norareidy Date: Tue, 30 Apr 2024 13:46:16 -0400 Subject: [PATCH 3/6] typo --- docs/query-builder.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/query-builder.txt b/docs/query-builder.txt index a47d40d0c..8ae9ce717 100644 --- a/docs/query-builder.txt +++ b/docs/query-builder.txt @@ -86,7 +86,7 @@ Retrieve Matching Documents --------------------------- This section includes query builder examples for read operations in the -following operator categoriess +following operator categories: - :ref:`Where method ` - :ref:`Logical conditionals ` From b5b19e748d7f50bdcebef5c775d40d4d4e51aee5 Mon Sep 17 00:00:00 2001 From: norareidy Date: Tue, 30 Apr 2024 13:48:47 -0400 Subject: [PATCH 4/6] wording --- docs/query-builder.txt | 2 +- docs/quick-start/view-data.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/query-builder.txt b/docs/query-builder.txt index 8ae9ce717..a61b2144b 100644 --- a/docs/query-builder.txt +++ b/docs/query-builder.txt @@ -74,7 +74,7 @@ To run the code examples in this guide, complete the :ref:`Quick Start ` tutorial to configure a web application, load sample datasets into your MongoDB deployment, and run the example code from a controller method. To see the expected code -output, follow the instructions in the optional :ref:`View your results as JSON documents +output, use the ``toJson()`` method shown in the optional :ref:`View your results as JSON documents ` step of the Quick Start. To perform read and write operations by using the query builder, import the diff --git a/docs/quick-start/view-data.txt b/docs/quick-start/view-data.txt index 95879038c..c60e48614 100644 --- a/docs/quick-start/view-data.txt +++ b/docs/quick-start/view-data.txt @@ -158,7 +158,7 @@ View MongoDB Data ->get(); foreach ($results as $movie) { - echo $movie->toJson() . '
\n'; + echo $movie->toJson() . '
\n'; } } From 9db7f7ba0cdbc6ad9536c2be60490fd5d68c196d Mon Sep 17 00:00:00 2001 From: norareidy Date: Tue, 30 Apr 2024 17:12:53 -0400 Subject: [PATCH 5/6] RR feedback --- docs/query-builder.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/query-builder.txt b/docs/query-builder.txt index a61b2144b..8b4be3245 100644 --- a/docs/query-builder.txt +++ b/docs/query-builder.txt @@ -74,8 +74,9 @@ To run the code examples in this guide, complete the :ref:`Quick Start ` tutorial to configure a web application, load sample datasets into your MongoDB deployment, and run the example code from a controller method. To see the expected code -output, use the ``toJson()`` method shown in the optional :ref:`View your results as JSON documents -` step of the Quick Start. +output as JSON documents, use the ``toJson()`` method shown in the optional +:ref:`View your results as JSON documents ` 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. From 05c0f4f954581c5e9af9b8b1e25edc0286aa4a08 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 6 May 2024 10:41:02 -0400 Subject: [PATCH 6/6] JT feedback --- docs/quick-start/view-data.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/quick-start/view-data.txt b/docs/quick-start/view-data.txt index c60e48614..86860944e 100644 --- a/docs/quick-start/view-data.txt +++ b/docs/quick-start/view-data.txt @@ -157,9 +157,7 @@ View MongoDB Data ->take(10) ->get(); - foreach ($results as $movie) { - echo $movie->toJson() . '
\n'; - } + return $results->toJson(); } .. step:: Start your Laravel application