質問編集履歴
3
試したことを追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -38,8 +38,18 @@
|
|
38
38
|
```
|
39
39
|
|
40
40
|
リレーション先の取得
|
41
|
+
|
42
|
+
userのidが1の場合
|
43
|
+
|
41
44
|
```
|
42
45
|
User::find(1)->account;
|
43
46
|
```
|
44
47
|
しかし上記を実行したら以下の警告が表示されます。
|
45
|
-
> 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
|
48
|
+
> 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
|
49
|
+
|
50
|
+
#### 試したこと
|
51
|
+
|
52
|
+
```PHP
|
53
|
+
return User::find(Auth::id())->account['admin'] === true;
|
54
|
+
|
55
|
+
```
|
2
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -20,8 +20,8 @@
|
|
20
20
|
$table->timestamps();
|
21
21
|
```
|
22
22
|
|
23
|
-
|
23
|
+
account_tabel
|
24
|
-
```
|
24
|
+
```account_table
|
25
25
|
$table->id();
|
26
26
|
$table->unsignedBigInteger('user_id');
|
27
27
|
$table->boolean('admin')->default(false);
|
@@ -29,9 +29,17 @@
|
|
29
29
|
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
30
30
|
```
|
31
31
|
|
32
|
+
リレーション定義
|
33
|
+
```PHP
|
34
|
+
public function account()
|
35
|
+
{
|
36
|
+
return $this->hasOne('App\Account');
|
37
|
+
}
|
38
|
+
```
|
39
|
+
|
32
40
|
リレーション先の取得
|
33
41
|
```
|
34
|
-
User::find(1)->
|
42
|
+
User::find(1)->account;
|
35
43
|
```
|
36
44
|
しかし上記を実行したら以下の警告が表示されます。
|
37
45
|
> 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
|
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,4 +7,31 @@
|
|
7
7
|
Gate::define('admin', function ($user) {
|
8
8
|
return $user->admin === true;
|
9
9
|
});
|
10
|
-
```
|
10
|
+
```
|
11
|
+
|
12
|
+
user_table
|
13
|
+
```user_table.php
|
14
|
+
$table->id();
|
15
|
+
$table->string('name');
|
16
|
+
$table->string('email')->unique();
|
17
|
+
$table->timestamp('email_verified_at')->nullable();
|
18
|
+
$table->string('password');
|
19
|
+
$table->rememberToken();
|
20
|
+
$table->timestamps();
|
21
|
+
```
|
22
|
+
|
23
|
+
acount_tabel
|
24
|
+
```acount_table
|
25
|
+
$table->id();
|
26
|
+
$table->unsignedBigInteger('user_id');
|
27
|
+
$table->boolean('admin')->default(false);
|
28
|
+
$table->timestamps();
|
29
|
+
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
30
|
+
```
|
31
|
+
|
32
|
+
リレーション先の取得
|
33
|
+
```
|
34
|
+
User::find(1)->acount;
|
35
|
+
```
|
36
|
+
しかし上記を実行したら以下の警告が表示されます。
|
37
|
+
> 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
|