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.
264
264
The ``SpaceExplorer`` model defines a ``BelongsToMany`` many to many
265
265
relationship with ``Planet`` as shown in the following example class:
266
266
267
- .. literalinclude:: /includes/eloquent-models/relationships/SpaceShipManyToMany .php
267
+ .. literalinclude:: /includes/eloquent-models/relationships/SpaceExplorerManyToMany .php
268
268
:language: php
269
269
:dedent:
270
270
@@ -433,7 +433,7 @@ created by running the code:
433
433
_id: ObjectId('65e207b9aa167d29a3048855')
434
434
}
435
435
]
436
- }
436
+ }
437
437
438
438
439
439
.. _laravel-relationship-cross-database
@@ -509,10 +509,10 @@ see sample MongoDB documents created by running the code:
509
509
:language: none
510
510
:visible: false
511
511
512
- +------+----------+
513
- | id | name |
514
- +------+----------+
515
- | 1234 | Nostromo |
516
- +------+----------+
517
-
512
+ +------+----------+
513
+ | id | name |
514
+ +------+----------+
515
+ | 1234 | Nostromo |
516
+ +------+----------+
517
+
518
518
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