Skip to content

Commit 2c7c1a8

Browse files
author
Chris Cho
committed
fix rst, organize sections
1 parent 7d1c13e commit 2c7c1a8

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

docs/eloquent-models.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ syntax to work with MongoDB as a database.
1919
This section contains guidance on how to use Eloquent models in
2020
{+odm-short+} to work with MongoDB in the following ways:
2121

22-
- :ref:`laravel-eloquent-model-relationships` shows how to add relationships
23-
between models
2422
- :ref:`laravel-schema-builder` shows how to manage indexes on your MongoDB
2523
collections
2624

docs/eloquent-models/schema-builder.txt

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. _laravel-eloquent-schema-builder:
1+
.. _laravel-schema-builder:
22

33
==============
44
Schema Builder
@@ -14,14 +14,14 @@ Schema Builder
1414
Overview
1515
--------
1616

17-
Laravel provides a ``Schema`` **facade** to access the schema builder, which
18-
lets you create and modify tables. Facades are static interfaces to classes
19-
that make the syntax more concise and improve testability.
17+
Laravel provides a **facade** to access the schema builder class ``Schema``,
18+
which lets you create and modify tables. Facades are static interfaces to
19+
classes that make the syntax more concise and improve testability.
2020

21-
{+odm-short+} supports index and collection management methods of the
22-
Laravel ``Schema`` facade.
21+
{+odm-short+} supports a subset of the index and collection management methods
22+
in the Laravel ``Schema`` facade.
2323

24-
To learn more about Laravel Facades, see `Facades <https://laravel.com/docs/{+laravel-docs-version+}/facades>`__
24+
To learn more about facades, see `Facades <https://laravel.com/docs/{+laravel-docs-version+}/facades>`__
2525
in the Laravel documentation.
2626

2727
The following sections describe the Laravel schema builder and functionality
@@ -37,15 +37,19 @@ available in {+odm-short+} and show examples of how to use them:
3737
Perform Laravel Migrations
3838
--------------------------
3939

40-
Laravel lets you create and make modifications to your database schema by
41-
running methods that call the ``Schema`` facade. The process of running this
42-
logic is called a migration.
40+
Laravel migrations let you programmatically create, modify, and delete
41+
your database schema by running methods included in the ``Schema`` facade.
42+
The following sections explain how to author a migration class when you use
43+
a MongoDB database and how to run them.
4344

44-
You can generate the migration class files by using the ``php artisan make:migration``
45-
command. Make the following changes to the generated files to perform the
46-
migration on your MongoDB database:
45+
Create a Migration Class
46+
~~~~~~~~~~~~~~~~~~~~~~~~
4747

48-
- Replace the ``Illuminate\Database\Schema\Blueprint`` import with
48+
You can create migration classes manually or generate them by using the
49+
``php artisan make:migration`` command. If you generate them, you must make the
50+
following changes to perform the schema changes on your MongoDB database:
51+
52+
- Replace the ``Illuminate\Database\Schema\Blueprint`` import with
4953
``MongoDB\Laravel\Schema\Blueprint``
5054
- Specify ``mongodb`` in the ``$connection`` field
5155
- Use only commands and syntax supported by {+odm-short+}
@@ -55,14 +59,23 @@ migration on your MongoDB database:
5559
Make sure you set ``DB_CONNECTION=mongodb`` in your ``.env`` configuration
5660
file so that PHP artisan performs the migration on the correct database.
5761

62+
The following example migration class file that creates a collection and
63+
index when you run the migration and drops it when you roll back the migration:
64+
65+
.. literalinclude:: /includes/schema-builder/astronauts_migration.php
66+
:language: php
67+
68+
Run or Roll Back a Migration
69+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70+
5871
To run the database migration from a class file, run the following PHP artisan
5972
command:
6073

6174
.. code-block:: bash
6275

6376
php artisan migrate --path=<path to your migration class file>
6477

65-
This artisan command runs the ``up()`` method in the class file to create
78+
This artisan command runs the ``up()`` function in the class file to create
6679
the collection and index in the database specified in the ``config/database.php``
6780
file.
6881

@@ -72,14 +85,12 @@ To roll back the migration, run the following PHP artisan command:
7285

7386
php artisan migrate:rollback --path=<path to your migration class file>
7487

75-
This command runs the ``down()`` method in the class file to drop the
88+
This command runs the ``down()`` function in the class file to drop the
7689
collection and related indexes.
7790

78-
The following example migration class file that creates a collection and
79-
index when you run the migration and drops it when you roll back the migration:
80-
81-
.. literalinclude:: /includes/schema-builder/astronauts_migration.php
82-
:language: php
91+
To learn more about Laravel migrations, see
92+
`Database: Migrations <https://laravel.com/docs/{+laravel-docs-version+}/migrations>`__
93+
in the Laravel documentation.
8394

8495
.. _laravel-eloquent-indexes:
8596

@@ -95,6 +106,9 @@ Manage Collections
95106

96107
TODO
97108

109+
Note that creating a collection is a noop unless it also creates an index
110+
since MongoDB automatically creates collections when you first write to them.
111+
98112
.. _laravel-eloquent-customize-collection:
99113

100114
Customize Collection Creation

0 commit comments

Comments
 (0)