質問編集履歴

3

追記2を修正

2018/05/19 09:50

投稿

karain
karain

スコア98

test CHANGED
File without changes
test CHANGED
@@ -100,10 +100,14 @@
100
100
 
101
101
  #追記2
102
102
 
103
-
103
+ 「dd($this->favorittings->where('microposts_id', $userId));」をした結果は以下のとおりです。
104
104
 
105
105
  ```
106
106
 
107
- dd($this->favorittings->where('microposts_id', $userId));
107
+ Collection {#237 ▼
108
+
109
+ #items: []
110
+
111
+ }
108
112
 
109
113
  ```

2

ddの結果を追記

2018/05/19 09:50

投稿

karain
karain

スコア98

test CHANGED
File without changes
test CHANGED
@@ -95,3 +95,15 @@
95
95
  }
96
96
 
97
97
  ```
98
+
99
+
100
+
101
+ #追記2
102
+
103
+
104
+
105
+ ```
106
+
107
+ dd($this->favorittings->where('microposts_id', $userId));
108
+
109
+ ```

1

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

2018/05/19 09:49

投稿

karain
karain

スコア98

test CHANGED
File without changes
test CHANGED
@@ -11,3 +11,87 @@
11
11
  上記ソースddしたところ、どんなデータを取得しているのかを確認することができませんでした。
12
12
 
13
13
  どのようにすれば中身を見ることができるでしょうか?
14
+
15
+
16
+
17
+ #追記
18
+
19
+
20
+
21
+ 前後のソースを貼り付けます
22
+
23
+ ```php
24
+
25
+ //View
26
+
27
+ @if(Auth::user()->is_favoritting($micropost->id))
28
+
29
+ {!! Form::open(['url' => route('favorites.destroy', ['id' => $micropost->id]), 'method' => 'delete']) !!}
30
+
31
+ {!! Form::submit('お気に入り解除', ['class' => 'btn btn-warning btn-xs']) !!}
32
+
33
+ {!! Form::close() !!}
34
+
35
+
36
+
37
+ @else
38
+
39
+ {!! Form::open(['url' => route('favorites.store', ['id' => $micropost->id]), 'method' => 'post']) !!}
40
+
41
+ {!! Form::submit('お気に入り', ['class' => 'btn btn-default btn-xs']) !!}
42
+
43
+ {!! Form::close() !!}
44
+
45
+
46
+
47
+ @endif
48
+
49
+ ```
50
+
51
+ 「$this->favorittings()->where('microposts_id', $userId」を
52
+
53
+ ddした結果は以下のとおりです
54
+
55
+ ```
56
+
57
+ BelongsToMany {#238 ▼
58
+
59
+ #table: "user_microposts"
60
+
61
+ #foreignPivotKey: "user_id"
62
+
63
+ #relatedPivotKey: "microposts_id"
64
+
65
+ #parentKey: "id"
66
+
67
+ #relatedKey: "id"
68
+
69
+ #relationName: "favorittings"
70
+
71
+ #pivotColumns: array:2 [▶]
72
+
73
+ #pivotWheres: []
74
+
75
+ #pivotWhereIns: []
76
+
77
+ #pivotValues: []
78
+
79
+ +withTimestamps: true
80
+
81
+ #pivotCreatedAt: null
82
+
83
+ #pivotUpdatedAt: null
84
+
85
+ #using: null
86
+
87
+ #accessor: "pivot"
88
+
89
+ #query: Builder {#239 ▶}
90
+
91
+ #parent: User {#215 ▶}
92
+
93
+ #related: User {#237 ▶}
94
+
95
+ }
96
+
97
+ ```