@@ -11,6 +11,12 @@ Schema Builder
11
11
.. meta::
12
12
:keywords: php framework, odm, code example, schema facade, php artisan, eloquent, blueprint, artisan, migrate
13
13
14
+ .. contents:: On this page
15
+ :local:
16
+ :backlinks: none
17
+ :depth: 2
18
+ :class: singlecol
19
+
14
20
Overview
15
21
--------
16
22
@@ -24,8 +30,8 @@ in the Laravel ``Schema`` facade.
24
30
To learn more about facades, see `Facades <https://laravel.com/docs/{+laravel-docs-version+}/facades>`__
25
31
in the Laravel documentation.
26
32
27
- The following sections describe the Laravel schema builder and functionality
28
- available in {+odm-short+} and show examples of how to use them:
33
+ The following sections describe the Laravel schema builder features available
34
+ in {+odm-short+} and show examples of how to use them:
29
35
30
36
- :ref:`<laravel-eloquent-migrations>`
31
37
- :ref:`<laravel-eloquent-collection-exists>`
@@ -66,17 +72,18 @@ following changes to perform the schema changes on your MongoDB database:
66
72
file so that PHP artisan performs the migration on the correct database.
67
73
68
74
The following example migration creates a collection and index when you run
69
- the migration and drops it when you roll back the migration:
75
+ the migration and drops them when you roll back the migration:
70
76
71
77
.. literalinclude:: /includes/schema-builder/astronauts_migration.php
78
+ :dedent:
72
79
:language: php
73
80
:emphasize-lines: 4, 10
74
81
75
82
Run or Roll Back a Migration
76
83
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
77
84
78
85
To run the database migration from a class file, run the following PHP artisan
79
- command:
86
+ command after replacing the placeholder :
80
87
81
88
.. code-block:: bash
82
89
@@ -86,7 +93,8 @@ This artisan command runs the ``up()`` function in the class file to create
86
93
the collection and index in the database specified in the ``config/database.php``
87
94
file.
88
95
89
- To roll back the migration, run the following PHP artisan command:
96
+ To roll back the migration, run the following PHP artisan command after
97
+ replacing the placeholder:
90
98
91
99
.. code-block:: bash
92
100
@@ -113,6 +121,7 @@ named ``telescopes`` exists:
113
121
114
122
.. literalinclude:: /includes/schema-builder/stars_migration.php
115
123
:language: php
124
+ :dedent:
116
125
:start-after: begin conditional create
117
126
:end-before: end conditional create
118
127
@@ -372,6 +381,7 @@ from the ``flights`` collection:
372
381
373
382
.. literalinclude:: /includes/schema-builder/flights_migration.php
374
383
:language: php
384
+ :dedent:
375
385
:start-after: begin drop index
376
386
:end-before: end drop index
377
387
0 commit comments