Skip to content

Commit 6d0ba9b

Browse files
author
Chris Cho
committed
fix
1 parent d2bbc98 commit 6d0ba9b

File tree

2 files changed

+50
-39
lines changed

2 files changed

+50
-39
lines changed

docs/eloquent-models/relationships.txt

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,8 @@ as shown in the following example class:
8484
:dedent:
8585

8686
The following sample code shows how you can instantiate a model for each class
87-
and add the relationship between them:
88-
89-
.. literalinclude:: /includes/eloquent-models/relationships/RelationshipController.php
90-
:language: php
91-
:dedent:
92-
:start-after: begin one-to-one save
93-
:end-before: end one-to-one save
94-
95-
The following sample code shows how you can access the related models by using
96-
the dynamic properties as defined in the example classes:
97-
87+
and add the relationship between them. Click the :guilabel:`Output` button to
88+
see sample MongoDB documents created by running the code::
9889

9990
.. io-code-block::
10091
.. input:: /includes/eloquent-models/relationships/RelationshipController.php
@@ -124,6 +115,15 @@ the dynamic properties as defined in the example classes:
124115
// ...
125116
}
126117

118+
The following sample code shows how you can access the related models by using
119+
the dynamic properties as defined in the example classes:
120+
121+
.. literalinclude:: /includes/eloquent-models/relationships/RelationshipController.php
122+
:language: php
123+
:dedent:
124+
:start-after: begin planet orbit dynamic property example
125+
:end-before: end planet orbit dynamic property example
126+
127127
.. _laravel-eloquent-relationship-one-to-many:
128128

129129
One to Many Relationship
@@ -170,26 +170,16 @@ example class:
170170
:dedent:
171171

172172
The following sample code shows how you can instantiate a model for each class
173-
and add the relationship between them:
174-
175-
.. literalinclude:: /includes/eloquent-models/relationships/RelationshipController.php
176-
:language: php
177-
:dedent:
178-
:start-after: begin one-to-many save
179-
:end-before: end one-to-many save
180-
181-
The following sample code shows how you can access the related models by using
182-
the dynamic properties as defined in the example classes. Click the
183-
:guilabel:`Output` button to see sample MongoDB documents created by running
184-
the code:
173+
and add the relationship between them. Click the :guilabel:`Output` button to
174+
see sample MongoDB documents created by running the code:
185175

186176
.. io-code-block::
187177

188178
.. input:: /includes/eloquent-models/relationships/RelationshipController.php
189179
:language: php
190180
:dedent:
191-
:start-after: begin planet moons dynamic property example
192-
:end-before: end planet moons dynamic property example
181+
:start-after: begin one-to-many save
182+
:end-before: end one-to-many save
193183

194184
.. output::
195185
:language: json
@@ -221,6 +211,16 @@ the code:
221211
}
222212
]
223213

214+
The following sample code shows how you can access the related models by using
215+
the dynamic properties as defined in the example classes.
216+
217+
.. literalinclude:: /includes/eloquent-models/relationships/RelationshipController.php
218+
:language: php
219+
:dedent:
220+
:start-after: begin planet moons dynamic property example
221+
:end-before: end planet moons dynamic property example
222+
223+
224224
.. _laravel-eloquent-relationship-many-to-many:
225225

226226
Many to Many Relationship
@@ -269,26 +269,16 @@ relationship with ``Planet`` as shown in the following example class:
269269
:dedent:
270270

271271
The following sample code shows how you can instantiate a model for each class
272-
and add the relationship between them:
273-
274-
.. literalinclude:: /includes/eloquent-models/relationships/RelationshipController.php
275-
:language: php
276-
:dedent:
277-
:start-after: begin many-to-many save
278-
:end-before: end many-to-many save
279-
280-
The following sample code shows how you can access the related models by using
281-
the dynamic properties as defined in the example classes. Click the
282-
:guilabel:`Output` button to see sample MongoDB documents created by running
283-
the code:
272+
and add the relationship between them. Click the :guilabel:`Output` button to
273+
see sample MongoDB documents created by running the code:
284274

285275
.. io-code-block::
286276

287277
.. input:: /includes/eloquent-models/relationships/RelationshipController.php
288278
:language: php
289279
:dedent:
290-
:start-after: begin many to many save
291-
:end-before: end many to many save
280+
:start-after: begin many-to-many save
281+
:end-before: end many-to-many save
292282

293283
.. output::
294284
:language: json
@@ -347,6 +337,16 @@ the code:
347337
}
348338
]
349339

340+
The following sample code shows how you can access the related models by using
341+
the dynamic properties as defined in the example classes.
342+
343+
.. literalinclude:: /includes/eloquent-models/relationships/RelationshipController.php
344+
:language: php
345+
:dedent:
346+
:start-after: begin many-to-many dynamic property example
347+
:end-before: end many-to-many dynamic property example
348+
349+
350350
.. _laravel-embedded-document-pattern:
351351

352352
Embedded Document Pattern

docs/includes/eloquent-models/relationships/RelationshipController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,19 @@ private function manyToMany()
103103
$explorer_jeanluc->planetsVisited()->attach($planet_mars);
104104
$explorer_jeanluc->planetsVisited()->attach($planet_jupiter);
105105
// end many-to-many save
106+
}
106107

108+
private function manyToManyDynamic()
109+
{
110+
// begin many-to-many dynamic property example
111+
$planet = Planet::first();
112+
$explorers = $planet->visitors;
113+
114+
$space_explorer = SpaceExplorer:first();
115+
$planets_visited = $space_explorer->planetsVisited;
116+
// end many-to-many dynamic property example
107117
}
118+
108119
private function embedsMany()
109120
{
110121
// begin embedsMany save

0 commit comments

Comments
 (0)