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

回答編集履歴

3

isFollowedも同様であることを追記

2020/04/13 01:01

投稿

Lulucom
Lulucom

スコア1904

answer CHANGED
@@ -4,8 +4,10 @@
4
4
  if ($is_following) { // フォロー中の場合
5
5
  ```
6
6
 
7
- (追記)`exists`の呼び出し結果を返すべきではないでしょうか。
7
+ (追記)`exists`の呼び出し結果を返すべきではないでしょうか。`isFollowed`メソッドも同様です。
8
8
 
9
+ Userモデル
10
+
9
11
  ```php
10
12
  public function isFollowing($user_id)
11
13
  {

2

文章を修正

2020/04/13 01:01

投稿

Lulucom
Lulucom

スコア1904

answer CHANGED
@@ -4,7 +4,7 @@
4
4
  if ($is_following) { // フォロー中の場合
5
5
  ```
6
6
 
7
- (追記)`exists`呼び出し結果を返すべきではないでしょうか。
7
+ (追記)`exists`呼び出し結果を返すべきではないでしょうか。
8
8
 
9
9
  ```php
10
10
  public function isFollowing($user_id)

1

isFollowingの修正案を追記

2020/04/13 01:00

投稿

Lulucom
Lulucom

スコア1904

answer CHANGED
@@ -2,4 +2,13 @@
2
2
 
3
3
  ```php
4
4
  if ($is_following) { // フォロー中の場合
5
+ ```
6
+
7
+ (追記)`exists`を呼び出し結果を返すべきではないでしょうか。
8
+
9
+ ```php
10
+ public function isFollowing($user_id)
11
+ {
12
+ return $this->follows()->where('followed_id', $user_id)->exists();
13
+ }
5
14
  ```