質問編集履歴
5
マイグレート
test
CHANGED
File without changes
|
test
CHANGED
@@ -230,6 +230,46 @@
|
|
230
230
|
|
231
231
|
```
|
232
232
|
|
233
|
+
###create_dept_table.php
|
234
|
+
|
235
|
+
```
|
236
|
+
|
237
|
+
class CreateDeptTable extends Migration
|
238
|
+
|
239
|
+
{
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
public function up()
|
244
|
+
|
245
|
+
{
|
246
|
+
|
247
|
+
Schema::create('departs', function (Blueprint $table) {
|
248
|
+
|
249
|
+
$table->increments('dept_id');
|
250
|
+
|
251
|
+
$table->string('dept_name');
|
252
|
+
|
253
|
+
});
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
public function down()
|
260
|
+
|
261
|
+
{
|
262
|
+
|
263
|
+
Schema::dropIfExists('departs');
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
```
|
272
|
+
|
233
273
|
|
234
274
|
|
235
275
|
### 試したこと
|
4
テーブル内容追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,7 +20,9 @@
|
|
20
20
|
|
21
21
|
![ブラウザ表示画面](94c3af891efb1ff09120df6ed9f08aa4.png)
|
22
22
|
|
23
|
-
|
23
|
+
![peopleテーブル](2be1ca4128dbdbd6c7bf5ed16204e603.png)
|
24
|
+
|
25
|
+
![departテーブル](d25a712a2ba86c9aad0bbb08c2a44349.png)
|
24
26
|
|
25
27
|
|
26
28
|
|
3
テーブル内容の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,15 +10,15 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
+
1対多 モデル
|
14
|
+
|
13
|
-
|
15
|
+
・Person.php(dept_name以外の要素全て)
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
|
17
|
-
|
17
|
+
・Depart.php(dept_idとdept_nameのみの要素)
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
-
![
|
21
|
+
![ブラウザ表示画面](94c3af891efb1ff09120df6ed9f08aa4.png)
|
22
22
|
|
23
23
|
|
24
24
|
|
2
モデルを修正しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -162,9 +162,11 @@
|
|
162
162
|
|
163
163
|
```
|
164
164
|
|
165
|
-
|
166
|
-
|
167
|
-
|
165
|
+
### Depart.php(該当箇所のみ)
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
```
|
168
170
|
|
169
171
|
<?php
|
170
172
|
|
@@ -192,7 +194,9 @@
|
|
192
194
|
|
193
195
|
```
|
194
196
|
|
195
|
-
|
197
|
+
### Person.php(該当箇所のみ)
|
198
|
+
|
199
|
+
```
|
196
200
|
|
197
201
|
class Person extends Model
|
198
202
|
|
1
モデルファイルを追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -164,6 +164,68 @@
|
|
164
164
|
|
165
165
|
|
166
166
|
|
167
|
+
```Depart.php
|
168
|
+
|
169
|
+
<?php
|
170
|
+
|
171
|
+
namespace App;
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
use Illuminate\Database\Eloquent\Model;
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
class Depart extends Model
|
180
|
+
|
181
|
+
{
|
182
|
+
|
183
|
+
public function person(){
|
184
|
+
|
185
|
+
return $this->hasMany('App\Person');
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
```
|
194
|
+
|
195
|
+
```Person.php
|
196
|
+
|
197
|
+
class Person extends Model
|
198
|
+
|
199
|
+
{
|
200
|
+
|
201
|
+
//guardedは入力の保護を設定するもの
|
202
|
+
|
203
|
+
protected $guarded = array('id');
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
public function depart()
|
208
|
+
|
209
|
+
{
|
210
|
+
|
211
|
+
return $this->belongsTo('App\Depart');
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
//timestampの無効化
|
218
|
+
|
219
|
+
public $timestamps = false;
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
```
|
226
|
+
|
227
|
+
|
228
|
+
|
167
229
|
### 試したこと
|
168
230
|
|
169
231
|
|