質問編集履歴
2
モデルの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -58,8 +58,65 @@
|
|
58
58
|
}
|
59
59
|
|
60
60
|
```
|
61
|
+
addressモデル
|
62
|
+
```
|
63
|
+
<?php
|
61
64
|
|
65
|
+
namespace App;
|
62
66
|
|
67
|
+
use Illuminate\Database\Eloquent\Model;
|
68
|
+
|
69
|
+
class Address extends Model
|
70
|
+
{
|
71
|
+
//
|
72
|
+
|
73
|
+
protected $fillable = [
|
74
|
+
|
75
|
+
name
|
76
|
+
|
77
|
+
];
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
```
|
82
|
+
Userモデル
|
83
|
+
```
|
84
|
+
<?php
|
85
|
+
|
86
|
+
namespace App;
|
87
|
+
|
88
|
+
use Illuminate\Foundation\Auth\User as Authenticatable;
|
89
|
+
|
90
|
+
class User extends Authenticatable
|
91
|
+
{
|
92
|
+
/**
|
93
|
+
* The attributes that are mass assignable.
|
94
|
+
*
|
95
|
+
* @var array
|
96
|
+
*/
|
97
|
+
protected $fillable = [
|
98
|
+
'name', 'email', 'password',
|
99
|
+
];
|
100
|
+
|
101
|
+
/**
|
102
|
+
* The attributes excluded from the model's JSON form.
|
103
|
+
*
|
104
|
+
* @var array
|
105
|
+
*/
|
106
|
+
protected $hidden = [
|
107
|
+
'password', 'remember_token',
|
108
|
+
];
|
109
|
+
|
110
|
+
public function address(){
|
111
|
+
|
112
|
+
return $this->hasOne('App\Address');
|
113
|
+
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
```
|
118
|
+
|
119
|
+
|
63
120
|
エラー:
|
64
121
|
```
|
65
122
|
ErrorException in Model.php line 3538:
|
1
マイグレーションファイルの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -21,7 +21,45 @@
|
|
21
21
|
});
|
22
22
|
|
23
23
|
```
|
24
|
+
addressマイグレーションファイル
|
24
25
|
|
26
|
+
```
|
27
|
+
<?php
|
28
|
+
|
29
|
+
use Illuminate\Database\Schema\Blueprint;
|
30
|
+
use Illuminate\Database\Migrations\Migration;
|
31
|
+
|
32
|
+
class CreateAddressesTable extends Migration
|
33
|
+
{
|
34
|
+
/**
|
35
|
+
* Run the migrations.
|
36
|
+
*
|
37
|
+
* @return void
|
38
|
+
*/
|
39
|
+
public function up()
|
40
|
+
{
|
41
|
+
Schema::create('addresses', function (Blueprint $table) {
|
42
|
+
$table->increments('id');
|
43
|
+
$table->integer('user_id')->unsigned()->nullable();
|
44
|
+
$table->string('name');
|
45
|
+
$table->timestamps();
|
46
|
+
});
|
47
|
+
}
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Reverse the migrations.
|
51
|
+
*
|
52
|
+
* @return void
|
53
|
+
*/
|
54
|
+
public function down()
|
55
|
+
{
|
56
|
+
Schema::drop('addresses');
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
```
|
61
|
+
|
62
|
+
|
25
63
|
エラー:
|
26
64
|
```
|
27
65
|
ErrorException in Model.php line 3538:
|