Skip to content

Commit d6397cb

Browse files
author
Chris Cho
committed
tweaks
1 parent dcf330f commit d6397cb

File tree

2 files changed

+45
-21
lines changed

2 files changed

+45
-21
lines changed

docs/quick-start/view-data.txt

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ View Sample MongoDB Data
1111
.. meta::
1212
:keywords: test connection, runnable, code example
1313

14-
Follow the steps in this section to create the
15-
To create a webpage that displays data from your database, you need
16-
to create a model, view, and controller.
17-
1814
.. procedure::
1915
:style: connected
2016

@@ -45,10 +41,10 @@ to create a model, view, and controller.
4541

4642
- Replace the ``Illuminate\Database\Eloquent\Model`` import with ``MongoDB\Laravel\Eloquent\Model``
4743
- Specify ``mongodb`` in the ``$connection`` field
48-
49-
44+
45+
5046
Your ``Movie.php`` file should contain the following code:
51-
47+
5248
.. code-block:: php
5349

5450
<?php
@@ -63,12 +59,12 @@ to create a model, view, and controller.
6359
}
6460

6561
.. step:: Add a Controller Function
66-
67-
Navigate to the ``app/Http/Controllers`` directory and open the
62+
63+
Navigate to the ``app/Http/Controllers`` directory and open the
6864
``MovieController.php`` file. Replace the ``show()`` function
6965
with the following code to retrieve results that match a
7066
database query and render it in the view:
71-
67+
7268
.. code-block:: php
7369

7470
public function show()
@@ -87,11 +83,11 @@ to create a model, view, and controller.
8783
Navigate to the ``routes`` directory and open the ``web.php`` file.
8884
Add an import for the ``MovieController`` and a route called
8985
``browse_movies`` as shown in the following code:
90-
86+
9187
.. code-block:: php
9288

93-
<?php
94-
89+
<?php
90+
9591
// ...
9692
use App\Http\Controllers\MovieController;
9793

@@ -145,9 +141,9 @@ to create a model, view, and controller.
145141

146142
Navigate to the application root directory and run the following command
147143
to start your PHP built-in web server:
148-
144+
149145
.. code-block:: bash
150-
146+
151147
php artisan serve
152148

153149
If the server starts successfully, you should see the following message:

docs/quick-start/write-data.txt

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ Post an API Request to Write Data
1414
.. procedure::
1515
:style: connected
1616

17-
.. step:: Add a Function to Store Data
17+
.. step:: Create the Function to Store Data
1818

19-
Navigate to your MovieController.php
19+
Add logic to save the data from a request in the ``MovieController.php``
20+
file in the ``app/Http/Controllers/`` directory. Replace the existing
21+
placeholder ``store()`` method with the following code:
2022

2123
.. code-block:: php
2224

@@ -30,7 +32,8 @@ Post an API Request to Write Data
3032

3133
.. step:: Add a Route for the Controller Function
3234

33-
In routes/api.php
35+
Add the API route to map to the ``store()`` method in the
36+
``routes/api.php`` file.
3437

3538
.. code-block:: php
3639

@@ -44,12 +47,12 @@ Post an API Request to Write Data
4447

4548

4649
.. step:: Update the Movie Model
47-
50+
4851
Add the movie detail fields to the ``$fillable`` array
4952
of the ``Movie`` model.
5053
Update the ``Movie`` class at ``app/Models/Movie.php``
5154

52-
55+
5356
.. code-block:: php
5457
:emphasize-lines: 4
5558

@@ -61,7 +64,32 @@ Post an API Request to Write Data
6164

6265
.. step:: Post a Request to the API
6366

64-
TODO:
67+
Create a file called ``movie.json`` and insert the following data:
68+
69+
.. code-block:: json
70+
71+
{
72+
"title": "The Laravel MongoDB Quick Start",
73+
"year": 2024,
74+
"runtime": 15,
75+
"imdb": {
76+
"rating": 9.5,
77+
"votes": 1
78+
},
79+
"plot": "This movie entry was created by running through the Laravel MongoDB Quick Start tutorial."
80+
}
81+
82+
Send the payload to the endpoint by running the following command in your shell:
83+
84+
.. code-block:: bash
85+
86+
curl -H "Content-Type: application/json" --data @movie.json http://localhost:8000/api/movies
87+
88+
.. step:: View the Data
89+
90+
Open ``http://127.0.0.1:8000/browse_movies`` in your web browser to view
91+
the movie information that you submitted. It should appear at the top of
92+
the results.
6593

6694
.. include:: /includes/quick-start/troubleshoot.rst
6795

0 commit comments

Comments
 (0)