8
8
use App \Models \Planet ;
9
9
use Illuminate \Http \Request ;
10
10
11
- use function view ;
12
-
13
- class PlanetController extends Controller
11
+ class RelationshipController extends Controller
14
12
{
15
13
private function oneToOne ()
16
14
{
@@ -36,75 +34,75 @@ private function oneToMany()
36
34
$ planet ->diameter_km = 142984 ;
37
35
$ planet ->save ();
38
36
39
- $ moon_1 = new Moon ();
40
- $ moon_1 ->name = 'Ganymede ' ;
41
- $ moon_1 ->orbital_period = 7.15 ;
37
+ $ moon1 = new Moon ();
38
+ $ moon1 ->name = 'Ganymede ' ;
39
+ $ moon1 ->orbital_period = 7.15 ;
42
40
43
- $ moon_2 = new Moon ();
44
- $ moon_2 ->name = 'Europa ' ;
45
- $ moon_2 ->orbital_period = 3.55 ;
41
+ $ moon2 = new Moon ();
42
+ $ moon2 ->name = 'Europa ' ;
43
+ $ moon2 ->orbital_period = 3.55 ;
46
44
47
- $ planet ->moons ()->save ($ moon_1 );
48
- $ planet ->moons ()->save ($ moon_2 );
45
+ $ planet ->moons ()->save ($ moon1 );
46
+ $ planet ->moons ()->save ($ moon2 );
49
47
// end one-to-many save
50
48
}
51
49
52
50
private function planetOrbitDynamic ()
53
51
{
54
52
// begin planet orbit dynamic property example
55
53
$ planet = Planet::first ();
56
- $ related_orbit = $ planet ->orbit ;
54
+ $ relatedOrbit = $ planet ->orbit ;
57
55
58
56
$ orbit = Orbit::first ();
59
- $ related_planet = $ orbit ->planet ;
57
+ $ relatedPlanet = $ orbit ->planet ;
60
58
// end planet orbit dynamic property example
61
59
}
62
60
63
61
private function planetMoonsDynamic ()
64
62
{
65
63
// begin planet moons dynamic property example
66
64
$ planet = Planet::first ();
67
- $ related_moons = $ planet ->moons ;
65
+ $ relatedMoons = $ planet ->moons ;
68
66
69
67
$ moon = Moon::first ();
70
- $ related_planet = $ moon ->planet ;
68
+ $ relatedPlanet = $ moon ->planet ;
71
69
// end planet moons dynamic property example
72
70
}
73
71
74
72
private function manyToMany ()
75
73
{
76
74
// begin many-to-many save
77
- $ planet_earth = new Planet ();
78
- $ planet_earth ->name = 'Earth ' ;
79
- $ planet_earth ->save ();
80
-
81
- $ planet_mars = new Planet ();
82
- $ planet_mars ->name = 'Mars ' ;
83
- $ planet_mars ->save ();
84
-
85
- $ planet_jupiter = new Planet ();
86
- $ planet_jupiter ->name = 'Jupiter ' ;
87
- $ planet_jupiter ->save ();
88
-
89
- $ explorer_tanya = new SpaceExplorer ();
90
- $ explorer_tanya ->name = 'Tanya Kirbuk ' ;
91
- $ explorer_tanya ->save ();
92
-
93
- $ explorer_mark = new SpaceExplorer ();
94
- $ explorer_mark ->name = 'Mark Watney ' ;
95
- $ explorer_mark ->save ();
96
-
97
- $ explorer_jeanluc = new SpaceExplorer ();
98
- $ explorer_jeanluc ->name = 'Jean-Luc Picard ' ;
99
- $ explorer_jeanluc ->save ();
100
-
101
- $ explorer_tanya ->planetsVisited ()->attach ($ planet_earth );
102
- $ explorer_tanya ->planetsVisited ()->attach ($ planet_jupiter );
103
- $ explorer_mark ->planetsVisited ()->attach ($ planet_earth );
104
- $ explorer_mark ->planetsVisited ()->attach ($ planet_mars );
105
- $ explorer_jeanluc ->planetsVisited ()->attach ($ planet_earth );
106
- $ explorer_jeanluc ->planetsVisited ()->attach ($ planet_mars );
107
- $ explorer_jeanluc ->planetsVisited ()->attach ($ planet_jupiter );
75
+ $ planetEarth = new Planet ();
76
+ $ planetEarth ->name = 'Earth ' ;
77
+ $ planetEarth ->save ();
78
+
79
+ $ planetMars = new Planet ();
80
+ $ planetMars ->name = 'Mars ' ;
81
+ $ planetMars ->save ();
82
+
83
+ $ planetJupiter = new Planet ();
84
+ $ planetJupiter ->name = 'Jupiter ' ;
85
+ $ planetJupiter ->save ();
86
+
87
+ $ explorerTanya = new SpaceExplorer ();
88
+ $ explorerTanya ->name = 'Tanya Kirbuk ' ;
89
+ $ explorerTanya ->save ();
90
+
91
+ $ explorerMark = new SpaceExplorer ();
92
+ $ explorerMark ->name = 'Mark Watney ' ;
93
+ $ explorerMark ->save ();
94
+
95
+ $ explorerJeanluc = new SpaceExplorer ();
96
+ $ explorerJeanluc ->name = 'Jean-Luc Picard ' ;
97
+ $ explorerJeanluc ->save ();
98
+
99
+ $ explorerTanya ->planetsVisited ()->attach ($ planetEarth );
100
+ $ explorerTanya ->planetsVisited ()->attach ($ planetJupiter );
101
+ $ explorerMark ->planetsVisited ()->attach ($ planetEarth );
102
+ $ explorerMark ->planetsVisited ()->attach ($ planetMars );
103
+ $ explorerJeanluc ->planetsVisited ()->attach ($ planetEarth );
104
+ $ explorerJeanluc ->planetsVisited ()->attach ($ planetMars );
105
+ $ explorerJeanluc ->planetsVisited ()->attach ($ planetJupiter );
108
106
// end many-to-many save
109
107
}
110
108
@@ -114,8 +112,8 @@ private function manyToManyDynamic()
114
112
$ planet = Planet::first ();
115
113
$ explorers = $ planet ->visitors ;
116
114
117
- $ space_explorer = SpaceExplorer:first ();
118
- $ planets_visited = $ space_explorer ->planetsVisited ;
115
+ $ spaceExplorer = SpaceExplorer:first ();
116
+ $ explored = $ spaceExplorer ->planetsVisited ;
119
117
// end many-to-many dynamic property example
120
118
}
121
119
@@ -126,16 +124,16 @@ private function embedsMany()
126
124
$ spaceship ->name = 'The Millenium Falcon ' ;
127
125
$ spaceship ->save ();
128
126
129
- $ cargo_spice = new Cargo ();
130
- $ cargo_spice ->name = 'spice ' ;
131
- $ cargo_spice ->weight = 50 ;
127
+ $ cargoSpice = new Cargo ();
128
+ $ cargoSpice ->name = 'spice ' ;
129
+ $ cargoSpice ->weight = 50 ;
132
130
133
- $ cargo_hyperdrive = new Cargo ();
134
- $ cargo_hyperdrive ->name = 'hyperdrive ' ;
135
- $ cargo_hyperdrive ->weight = 25 ;
131
+ $ cargoHyperdrive = new Cargo ();
132
+ $ cargoHyperdrive ->name = 'hyperdrive ' ;
133
+ $ cargoHyperdrive ->weight = 25 ;
136
134
137
- $ spaceship ->cargo ()->attach ($ cargo_spice );
138
- $ spaceship ->cargo ()->attach ($ cargo_hyperdrive );
135
+ $ spaceship ->cargo ()->attach ($ cargoSpice );
136
+ $ spaceship ->cargo ()->attach ($ cargoHyperdrive );
139
137
// end embedsMany save
140
138
}
141
139
@@ -147,14 +145,14 @@ private function crossDatabase()
147
145
$ spaceship ->name = 'Nostromo ' ;
148
146
$ spaceship ->save ();
149
147
150
- $ passenger_ellen = new Passenger ();
151
- $ passenger_ellen ->name = 'Ellen Ripley ' ;
148
+ $ passengerEllen = new Passenger ();
149
+ $ passengerEllen ->name = 'Ellen Ripley ' ;
152
150
153
- $ passenger_dwayne = new Passenger ();
154
- $ passenger_dwayne ->name = 'Dwayne Hicks ' ;
151
+ $ passengerDwayne = new Passenger ();
152
+ $ passengerDwayne ->name = 'Dwayne Hicks ' ;
155
153
156
- $ spaceship ->passengers ()->save ($ passenger_ellen );
157
- $ spaceship ->passengers ()->save ($ passenger_dwayne );
154
+ $ spaceship ->passengers ()->save ($ passengerEllen );
155
+ $ spaceship ->passengers ()->save ($ passengerDwayne );
158
156
// end cross-database save
159
157
}
160
158
@@ -163,20 +161,14 @@ private function crossDatabase()
163
161
*/
164
162
public function store (Request $ request )
165
163
{
166
- oneToMany ();
167
-
168
- return ;
169
164
}
170
165
171
166
/**
172
167
* Display the specified resource.
173
168
*/
174
169
public function show ()
175
170
{
176
- return view ('browse_planets ' , [
177
- 'planets ' => Planet::take (10 )
178
- ->get (),
179
- ]);
171
+ return 'ok ' ;
180
172
}
181
173
182
174
/**
0 commit comments