質問編集履歴
1
リレーションとtimeline()メソッドがどのクラスに実装されているのかを修正・追加いたしました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -9,9 +9,11 @@
|
|
9
9
|
### 試したこと
|
10
10
|
|
11
11
|
```ここに言語を入力
|
12
|
+
class UserController extends Controller {
|
12
|
-
public function timeline()
|
13
|
+
public function timeline()
|
13
|
-
{
|
14
|
+
{
|
14
|
-
|
15
|
+
$posts = Post::where('user_id', Auth::user()->followings)->get();
|
16
|
+
}
|
15
17
|
}
|
16
18
|
```
|
17
19
|
上記の第二引数に適切な値を記述すれば、取得できると考えているのですが、その値の検討がつきません。
|
@@ -34,6 +36,10 @@
|
|
34
36
|
```ここに言語を入力
|
35
37
|
User.php
|
36
38
|
|
39
|
+
public function posts()
|
40
|
+
{
|
41
|
+
return $this->hasMany('App\Post');
|
42
|
+
}
|
37
43
|
public function followings(): BelongsToMany
|
38
44
|
{
|
39
45
|
return $this->belongsToMany('App\User', 'follows', 'follower_id', 'followee_id')->withTimestamps();
|