質問編集履歴
3
試したことを追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -78,6 +78,12 @@
|
|
78
78
|
|
79
79
|
リレーション先の取得
|
80
80
|
|
81
|
+
|
82
|
+
|
83
|
+
userのidが1の場合
|
84
|
+
|
85
|
+
|
86
|
+
|
81
87
|
```
|
82
88
|
|
83
89
|
User::find(1)->account;
|
@@ -87,3 +93,17 @@
|
|
87
93
|
しかし上記を実行したら以下の警告が表示されます。
|
88
94
|
|
89
95
|
> PHP Notice: PDO::prepare(): send of 57 bytes failed with errno=32 Broken pipe in /Laravel_practice/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 331
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
#### 試したこと
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
```PHP
|
104
|
+
|
105
|
+
return User::find(Auth::id())->account['admin'] === true;
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
```
|
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -42,9 +42,9 @@
|
|
42
42
|
|
43
43
|
|
44
44
|
|
45
|
-
acount_tabel
|
45
|
+
account_tabel
|
46
46
|
|
47
|
-
```acount_table
|
47
|
+
```account_table
|
48
48
|
|
49
49
|
$table->id();
|
50
50
|
|
@@ -60,11 +60,27 @@
|
|
60
60
|
|
61
61
|
|
62
62
|
|
63
|
+
リレーション定義
|
64
|
+
|
65
|
+
```PHP
|
66
|
+
|
67
|
+
public function account()
|
68
|
+
|
69
|
+
{
|
70
|
+
|
71
|
+
return $this->hasOne('App\Account');
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
```
|
76
|
+
|
77
|
+
|
78
|
+
|
63
79
|
リレーション先の取得
|
64
80
|
|
65
81
|
```
|
66
82
|
|
67
|
-
User::find(1)->acount;
|
83
|
+
User::find(1)->account;
|
68
84
|
|
69
85
|
```
|
70
86
|
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -17,3 +17,57 @@
|
|
17
17
|
});
|
18
18
|
|
19
19
|
```
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
user_table
|
24
|
+
|
25
|
+
```user_table.php
|
26
|
+
|
27
|
+
$table->id();
|
28
|
+
|
29
|
+
$table->string('name');
|
30
|
+
|
31
|
+
$table->string('email')->unique();
|
32
|
+
|
33
|
+
$table->timestamp('email_verified_at')->nullable();
|
34
|
+
|
35
|
+
$table->string('password');
|
36
|
+
|
37
|
+
$table->rememberToken();
|
38
|
+
|
39
|
+
$table->timestamps();
|
40
|
+
|
41
|
+
```
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
acount_tabel
|
46
|
+
|
47
|
+
```acount_table
|
48
|
+
|
49
|
+
$table->id();
|
50
|
+
|
51
|
+
$table->unsignedBigInteger('user_id');
|
52
|
+
|
53
|
+
$table->boolean('admin')->default(false);
|
54
|
+
|
55
|
+
$table->timestamps();
|
56
|
+
|
57
|
+
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
58
|
+
|
59
|
+
```
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
リレーション先の取得
|
64
|
+
|
65
|
+
```
|
66
|
+
|
67
|
+
User::find(1)->acount;
|
68
|
+
|
69
|
+
```
|
70
|
+
|
71
|
+
しかし上記を実行したら以下の警告が表示されます。
|
72
|
+
|
73
|
+
> PHP Notice: PDO::prepare(): send of 57 bytes failed with errno=32 Broken pipe in /Laravel_practice/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 331
|