Skip to content

DOCSP-37618: Usage Examples landing page #2767

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 28 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
9 changes: 8 additions & 1 deletion docs/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Laravel MongoDB
:maxdepth: 1

/quick-start
/usage-examples
/retrieve
/eloquent-models
/query-builder
Expand Down Expand Up @@ -46,10 +47,16 @@ Learn how to add {+odm-short+} to a Laravel web application, connect to
MongoDB hosted on MongoDB Atlas, and begin working with data in the
:ref:`laravel-quick-start` section.

Usage Examples
--------------

See fully runnable code examples and explanations of common
MongoDB operations in the :ref:`laravel-usage-examples` section.

Fundamentals
------------

To learn how to perform the following tasks by using the {+odm-short+},
To learn how to perform the following tasks by using {+odm-short+},
see the following content:

- :ref:`laravel-fundamentals-retrieve`
Expand Down
67 changes: 67 additions & 0 deletions docs/usage-examples.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
.. _laravel-usage-examples:

==============
Usage Examples
==============

.. facet::
:name: genre
:values: tutorial

.. meta::
:keywords: set up, runnable, code example

.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol

Overview
--------

Usage examples show runnable code examples to demonstrate frequently used MongoDB
operations. Each usage example includes the following components:

- Explanation of the MongoDB operation
- Example controller code that runs the MongoDB operation
- Example view code that renders the result
- Output displayed by the view

How to Run the Usage Examples
-----------------------------

The usage examples are designed to run operations on a MongoDB deployment that contains
the MongoDB Atlas sample datasets. When you run the example code without this sample data,
the output might not match.

You can run the usage examples from the Laravel web application and MongoDB Atlas cluster that you
set up in the :ref:`laravel-quick-start` guide. After completing the Quick Start, ensure that your
application meets the following requirements:

- Connects to the ``movies`` collection in the Atlas sample datasets
- Contains the ``MovieController.php`` and ``browse_movies.blade.php`` files
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

I think it could be easier to verify the requirements as Laravel web app components rather than existence of the collection and files. I think it's also missing mention of the API controller (used for storing data - see https://www.mongodb.com/docs/drivers/php/laravel-mongodb/current/quick-start/write-data/). E.g.

"... application contains the following components:"

  • Configuration to use an Atlas cluster that contains the sample datasets
  • Movie model configured to use the MongoDB database
  • Movie view that lists the results
  • HTTP and API controller endpoints for displaying and storing Movie data
    "


Then, follow this tutorial to add the usage example code to your Laravel application and view
the expected results.

.. procedure::
:style: connected

.. step:: Add the Controller Code to Your Application

Copy the example code from the :guilabel:`Controller File Code` tab on the usage example
page and paste it into the ``MovieController.php`` file.

.. step:: Add the View Code to Your Application

Copy the example code from the :guilabel:`View File Code` tab on the usage example page and
paste it into the ``browse_movies.blade.php`` file.

.. step:: Run the Usage Example Code

To run the example controller code and view the results, follow the instructions on the
usage example page.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

I think presenting this information might not make sense before a reader gets the chance to see a Usage Example page. As mentioned in a previous comment, it should delegate some of the explanation to the specific usage examples since they may differ depending on the operation.

Start with information on when this applies, e.g.
"
Each Usage Example page features example code in the Controller File Code and View File Code tabs that you can copy and paste into your Laravel application.

Unless otherwise specified, you can add Usage Example sample code to your application by performing the following actions:

  • Add the code from the Controller File Code tab to your MovieController.php file in the ... directory
  • Add the code from the View File Code tab to your browse_movies.blade.php file in the ... directory.

Follow the instructions on the Usage Example page to run the code and view the output.
"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay, so including tutorial steps doesn't seem necessary; changed


After completing these steps, you can see the output described in the **Expected Output** section
of the corresponding usage example.