Skip to content

Commit b8b54dd

Browse files
author
Chris Cho
committed
code snippet fixes
1 parent d8609e9 commit b8b54dd

11 files changed

+78
-70
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Models;
46

57
use MongoDB\Laravel\Eloquent\Model;
68

79
class Cargo extends Model
810
{
9-
protected $connection = 'mongodb';
11+
protected $connection = 'mongodb';
1012
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Models;
46

57
use MongoDB\Laravel\Eloquent\Model;
68
use MongoDB\Laravel\Relations\BelongsTo;
79

810
class Moon extends Model
911
{
10-
protected $connection = 'mongodb';
11-
12-
public function planet(): BelongsTo
13-
{
14-
return $this->belongsTo(Planet::class);
15-
}
12+
protected $connection = 'mongodb';
1613

14+
public function planet(): BelongsTo
15+
{
16+
return $this->belongsTo(Planet::class);
17+
}
1718
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Models;
46

57
use MongoDB\Laravel\Eloquent\Model;
68
use MongoDB\Laravel\Relations\BelongsTo;
79

810
class Orbit extends Model
911
{
10-
protected $connection = 'mongodb';
11-
12-
public function planet(): BelongsTo
13-
{
14-
return $this->belongsTo(Planet::class);
15-
}
12+
protected $connection = 'mongodb';
1613

14+
public function planet(): BelongsTo
15+
{
16+
return $this->belongsTo(Planet::class);
17+
}
1718
}
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Models;
46

57
use MongoDB\Laravel\Eloquent\Model;
6-
use MongoDB\Database\Relations\BelongsTo;
8+
use MongoDB\Laravel\Relations\BelongsTo;
79

810
class Passenger extends Model
911
{
10-
protected $connection = 'mongodb';
11-
12-
public function spaceship(): BelongsTo
13-
{
14-
return $this->BelongsTo(SpaceShip::class);
15-
}
12+
protected $connection = 'mongodb';
1613

14+
public function spaceship(): BelongsTo
15+
{
16+
return $this->belongsTo(SpaceShip::class);
17+
}
1718
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Models;
46

57
use MongoDB\Laravel\Eloquent\Model;
68
use MongoDB\Laravel\Relations\BelongsToMany;
79

810
class Planet extends Model
911
{
10-
protected $connection = 'mongodb';
11-
12-
public function visitors(): BelongsToMany
13-
{
14-
return $this->belongsToMany(SpaceExplorer::class);
15-
}
12+
protected $connection = 'mongodb';
1613

14+
public function visitors(): BelongsToMany
15+
{
16+
return $this->belongsToMany(SpaceExplorer::class);
17+
}
1718
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Models;
46

57
use MongoDB\Laravel\Eloquent\Model;
68
use MongoDB\Laravel\Relations\HasMany;
79

810
class Planet extends Model
911
{
10-
protected $connection = 'mongodb';
11-
12-
public function moons(): HasMany
13-
{
14-
return $this->hasMany(Moon::class);
15-
}
12+
protected $connection = 'mongodb';
1613

14+
public function moons(): HasMany
15+
{
16+
return $this->hasMany(Moon::class);
17+
}
1718
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Models;
46

57
use MongoDB\Laravel\Eloquent\Model;
68
use MongoDB\Laravel\Relations\HasOne;
79

810
class Planet extends Model
911
{
10-
protected $connection = 'mongodb';
11-
12-
public function orbit(): HasOne
13-
{
14-
return $this->hasOne(Orbit::class);
15-
}
12+
protected $connection = 'mongodb';
1613

14+
public function orbit(): HasOne
15+
{
16+
return $this->hasOne(Orbit::class);
17+
}
1718
}

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Http\Controllers;
46

5-
use App\Models\Planet;
67
use App\Models\Orbit;
8+
use App\Models\Planet;
79
use Illuminate\Http\Request;
810

11+
use function view;
12+
913
class PlanetController extends Controller
1014
{
11-
1215
private function oneToOne()
1316
{
1417
// begin one-to-one save
@@ -79,7 +82,7 @@ private function manyToMany()
7982
$planet_mars->name = 'Mars';
8083
$planet_mars->save();
8184

82-
$planet_jupiter= new Planet();
85+
$planet_jupiter = new Planet();
8386
$planet_jupiter->name = 'Jupiter';
8487
$planet_jupiter->save();
8588

@@ -124,19 +127,18 @@ private function embedsMany()
124127
$spaceship->save();
125128

126129
$cargo_spice = new Cargo();
127-
$cargo_spice->name = "spice";
130+
$cargo_spice->name = 'spice';
128131
$cargo_spice->weight = 50;
129132

130133
$cargo_hyperdrive = new Cargo();
131-
$cargo_hyperdrive->name = "hyperdrive";
134+
$cargo_hyperdrive->name = 'hyperdrive';
132135
$cargo_hyperdrive->weight = 25;
133136

134137
$spaceship->cargo()->attach($cargo_spice);
135138
$spaceship->cargo()->attach($cargo_hyperdrive);
136139
// end embedsMany save
137140
}
138141

139-
140142
private function crossDatabase()
141143
{
142144
// begin cross-database save
@@ -156,7 +158,6 @@ private function crossDatabase()
156158
// end cross-database save
157159
}
158160

159-
160161
/**
161162
* Store a newly created resource in storage.
162163
*/
@@ -167,16 +168,14 @@ public function store(Request $request)
167168
return;
168169
}
169170

170-
171-
172171
/**
173172
* Display the specified resource.
174173
*/
175174
public function show()
176175
{
177176
return view('browse_planets', [
178-
'planets' => Planet::take(10)
179-
->get()
177+
'planets' => Planet::take(10)
178+
->get(),
180179
]);
181180
}
182181

@@ -185,22 +184,19 @@ public function show()
185184
*/
186185
public function edit(Planet $planet)
187186
{
188-
//
189187
}
190188

191189
/**
192190
* Update the specified resource in storage.
193191
*/
194192
public function update(Request $request, Planet $planet)
195193
{
196-
//
197194
}
198195

199196
/**
200197
* Remove the specified resource from storage.
201198
*/
202199
public function destroy(Planet $planet)
203200
{
204-
//
205201
}
206202
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Models;
46

57
use MongoDB\Laravel\Eloquent\Model;
68
use MongoDB\Laravel\Relations\BelongsToMany;
79

810
class SpaceExplorer extends Model
911
{
10-
protected $connection = 'mongodb';
11-
12-
public function planetsVisited(): BelongsToMany
13-
{
14-
return $this->belongsToMany(Planet::class);
15-
}
12+
protected $connection = 'mongodb';
1613

14+
public function planetsVisited(): BelongsToMany
15+
{
16+
return $this->belongsToMany(Planet::class);
17+
}
1718
}
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Models;
46

57
use Illuminate\Database\Eloquent\Model;
@@ -8,12 +10,12 @@
810

911
class SpaceShip extends Model
1012
{
11-
protected $connection = 'mysql';
13+
use HybridRelations;
1214

13-
public $primaryKey = 'id';
14-
public function passengers(): HasMany
15-
{
16-
return $this->hasMany(Passenger::class);
17-
}
15+
protected $connection = 'sqlite';
1816

17+
public function passengers(): HasMany
18+
{
19+
return $this->hasMany(Passenger::class);
20+
}
1921
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Models;
46

57
use MongoDB\Laravel\Eloquent\Model;
68
use MongoDB\Laravel\Relations\EmbedsMany;
79

810
class SpaceShip extends Model
911
{
10-
protected $connection = 'mongodb';
11-
12-
public function cargo():EmbedsMany
13-
{
14-
return $this->embedsMany(Cargo::class);
15-
}
12+
protected $connection = 'mongodb';
1613

14+
public function cargo(): EmbedsMany
15+
{
16+
return $this->embedsMany(Cargo::class);
17+
}
1718
}

0 commit comments

Comments
 (0)