teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

リレーションとtimeline()メソッドがどのクラスに実装されているのかを修正・追加いたしました。

2020/08/09 06:21

投稿

kensuke0122
kensuke0122

スコア0

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
-   $posts = Post::where('user_id', Auth::user()->followings)->get();
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();