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

質問編集履歴

3

追記2を修正

2018/05/19 09:50

投稿

karain
karain

スコア98

title CHANGED
File without changes
body CHANGED
@@ -49,7 +49,9 @@
49
49
  ```
50
50
 
51
51
  #追記2
52
-
52
+ 「dd($this->favorittings->where('microposts_id', $userId));」をした結果は以下のとおりです。
53
53
  ```
54
- dd($this->favorittings->where('microposts_id', $userId));
54
+ Collection {#237 ▼
55
+ #items: []
56
+ }
55
57
  ```

2

ddの結果を追記

2018/05/19 09:50

投稿

karain
karain

スコア98

title CHANGED
File without changes
body CHANGED
@@ -46,4 +46,10 @@
46
46
  #parent: User {#215 ▶}
47
47
  #related: User {#237 ▶}
48
48
  }
49
+ ```
50
+
51
+ #追記2
52
+
53
+ ```
54
+ dd($this->favorittings->where('microposts_id', $userId));
49
55
  ```

1

前後のソースとddの結果を貼り付け

2018/05/19 09:49

投稿

karain
karain

スコア98

title CHANGED
File without changes
body CHANGED
@@ -4,4 +4,46 @@
4
4
  $this->favorittings()->where('microposts_id', $userId)->exists();
5
5
  ```
6
6
  上記ソースddしたところ、どんなデータを取得しているのかを確認することができませんでした。
7
- どのようにすれば中身を見ることができるでしょうか?
7
+ どのようにすれば中身を見ることができるでしょうか?
8
+
9
+ #追記
10
+
11
+ 前後のソースを貼り付けます
12
+ ```php
13
+ //View
14
+ @if(Auth::user()->is_favoritting($micropost->id))
15
+ {!! Form::open(['url' => route('favorites.destroy', ['id' => $micropost->id]), 'method' => 'delete']) !!}
16
+ {!! Form::submit('お気に入り解除', ['class' => 'btn btn-warning btn-xs']) !!}
17
+ {!! Form::close() !!}
18
+
19
+ @else
20
+ {!! Form::open(['url' => route('favorites.store', ['id' => $micropost->id]), 'method' => 'post']) !!}
21
+ {!! Form::submit('お気に入り', ['class' => 'btn btn-default btn-xs']) !!}
22
+ {!! Form::close() !!}
23
+
24
+ @endif
25
+ ```
26
+ 「$this->favorittings()->where('microposts_id', $userId」を
27
+ ddした結果は以下のとおりです
28
+ ```
29
+ BelongsToMany {#238 ▼
30
+ #table: "user_microposts"
31
+ #foreignPivotKey: "user_id"
32
+ #relatedPivotKey: "microposts_id"
33
+ #parentKey: "id"
34
+ #relatedKey: "id"
35
+ #relationName: "favorittings"
36
+ #pivotColumns: array:2 [▶]
37
+ #pivotWheres: []
38
+ #pivotWhereIns: []
39
+ #pivotValues: []
40
+ +withTimestamps: true
41
+ #pivotCreatedAt: null
42
+ #pivotUpdatedAt: null
43
+ #using: null
44
+ #accessor: "pivot"
45
+ #query: Builder {#239 ▶}
46
+ #parent: User {#215 ▶}
47
+ #related: User {#237 ▶}
48
+ }
49
+ ```