File tree Expand file tree Collapse file tree 3 files changed +44
-8
lines changed
includes/eloquent-models/relationships Expand file tree Collapse file tree 3 files changed +44
-8
lines changed Original file line number Diff line number Diff line change @@ -264,7 +264,7 @@ many relationship with and a ``SpaceExplorer`` model.
264264The ``SpaceExplorer`` model defines a ``BelongsToMany`` many to many
265265relationship with ``Planet`` as shown in the following example class:
266266
267- .. literalinclude:: /includes/eloquent-models/relationships/SpaceShipManyToMany .php
267+ .. literalinclude:: /includes/eloquent-models/relationships/SpaceExplorerManyToMany .php
268268 :language: php
269269 :dedent:
270270
@@ -433,7 +433,7 @@ created by running the code:
433433 _id: ObjectId('65e207b9aa167d29a3048855')
434434 }
435435 ]
436- }
436+ }
437437
438438
439439.. _laravel-relationship-cross-database
@@ -509,10 +509,10 @@ see sample MongoDB documents created by running the code:
509509 :language: none
510510 :visible: false
511511
512- +------+----------+
513- | id | name |
514- +------+----------+
515- | 1234 | Nostromo |
516- +------+----------+
517-
512+ +------+----------+
513+ | id | name |
514+ +------+----------+
515+ | 1234 | Nostromo |
516+ +------+----------+
517+
518518
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Models ;
4+
5+ use MongoDB \Laravel \Eloquent \Model ;
6+ use MongoDB \Database \Relations \BelongsTo ;
7+
8+ class Passenger extends Model
9+ {
10+ protected $ connection = 'mongodb ' ;
11+
12+ public function spaceship (): BelongsTo
13+ {
14+ return $ this ->BelongsTo (SpaceShip::class);
15+ }
16+
17+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Models ;
4+
5+ use Illuminate \Database \Eloquent \Model ;
6+ use Illuminate \Database \Eloquent \Relations \HasMany ;
7+ use MongoDB \Laravel \Eloquent \HybridRelations ;
8+
9+ class SpaceShip extends Model
10+ {
11+ protected $ connection = 'mysql ' ;
12+
13+ public $ primaryKey = 'id ' ;
14+ public function passengers (): HasMany
15+ {
16+ return $ this ->hasMany (Passenger::class);
17+ }
18+
19+ }
You can’t perform that action at this time.
0 commit comments