質問編集履歴
2
edit
title
CHANGED
File without changes
|
body
CHANGED
@@ -56,11 +56,18 @@
|
|
56
56
|
```php
|
57
57
|
$post = Post::find($id);
|
58
58
|
$comments = $post->comment;
|
59
|
-
$comments_user = $post->comment->user->name;
|
59
|
+
$comments_user = $post->comment->user->name; //これや
|
60
|
+
$comments_user = $comments->user->name; //これを試した
|
60
61
|
```
|
61
62
|
|
62
63
|
`$comments = $post->comment;`までは取得することができ、該当するデータ`post_id`, `user_id`, `content`を確認することができた。
|
64
|
+
|
63
65
|
|
66
|
+
## 発生エラー
|
67
|
+
```
|
68
|
+
Property [user] does not exist on this collection instance.
|
69
|
+
```
|
64
70
|
|
71
|
+
|
65
72
|
### 環境
|
66
73
|
Laravel 8.x
|
1
edit
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Laravelでコメントした人の情報をuser_idを元にユーザ名を表示させたい。
|
2
2
|
また、この時Bladeで表示させるのではなく、Controllerで変数に保持したい。
|
3
3
|
|
4
|
-
|
4
|
+
テーブル名: `comments`
|
5
5
|
```php
|
6
6
|
$table->id();
|
7
7
|
$table->unsignedBigInteger('post_id');
|
@@ -12,7 +12,7 @@
|
|
12
12
|
$table->timestamps();
|
13
13
|
```
|
14
14
|
|
15
|
-
|
15
|
+
テーブル名: `users`
|
16
16
|
|
17
17
|
```php
|
18
18
|
$table->id();
|
@@ -59,6 +59,8 @@
|
|
59
59
|
$comments_user = $post->comment->user->name;
|
60
60
|
```
|
61
61
|
|
62
|
+
`$comments = $post->comment;`までは取得することができ、該当するデータ`post_id`, `user_id`, `content`を確認することができた。
|
62
63
|
|
64
|
+
|
63
65
|
### 環境
|
64
66
|
Laravel 8.x
|