質問編集履歴
2
var_dumpした結果を追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -256,7 +256,53 @@
|
|
256
256
|
|
257
257
|
```
|
258
258
|
|
259
|
-
|
259
|
+
$userをvar_dump
|
260
|
+
|
261
|
+
```
|
262
|
+
|
263
|
+
object(App\Models\User)[302]
|
264
|
+
|
265
|
+
protected 'fillable' =>
|
266
|
+
|
267
|
+
array (size=6)
|
268
|
+
|
269
|
+
0 => string 'name' (length=4)
|
270
|
+
|
271
|
+
1 => string 'email' (length=5)
|
272
|
+
|
273
|
+
2 => string 'password' (length=8)
|
274
|
+
|
275
|
+
3 => string 'screen_name' (length=11)
|
276
|
+
|
277
|
+
4 => string 'team' (length=4)
|
278
|
+
|
279
|
+
5 => string 'profile_image' (length=13)
|
280
|
+
|
281
|
+
protected 'hidden' =>
|
282
|
+
|
283
|
+
array (size=2)
|
284
|
+
|
285
|
+
0 => string 'password' (length=8)
|
286
|
+
|
287
|
+
1 => string 'remember_token' (length=14)
|
288
|
+
|
289
|
+
protected 'casts' =>
|
290
|
+
|
291
|
+
array (size=1)
|
292
|
+
|
293
|
+
'email_verified_at' => string 'datetime' (length=8)
|
294
|
+
|
295
|
+
protected 'connection' => null
|
296
|
+
|
297
|
+
protected 'table' => null
|
298
|
+
|
299
|
+
protected 'primaryKey' => string 'id' (length=2)
|
300
|
+
|
301
|
+
protected 'keyType' => string 'int' (length=3)
|
302
|
+
|
303
|
+
public 'incrementing' => boolean true
|
304
|
+
|
305
|
+
```
|
260
306
|
|
261
307
|
### 試したこと
|
262
308
|
|
1
viewとrouteファイルを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -118,9 +118,7 @@
|
|
118
118
|
|
119
119
|
User.php
|
120
120
|
|
121
|
-
```
|
121
|
+
```
|
122
|
-
|
123
|
-
|
124
122
|
|
125
123
|
//フォローする
|
126
124
|
|
@@ -204,6 +202,62 @@
|
|
204
202
|
|
205
203
|
|
206
204
|
|
205
|
+
view\users\index.blade.php
|
206
|
+
|
207
|
+
```view\users\index.blade.php
|
208
|
+
|
209
|
+
@if(auth()->user()->isFollowed($user->id))
|
210
|
+
|
211
|
+
<div class="px-2">
|
212
|
+
|
213
|
+
<span class="px-1 bg-secondary text-light">フォローされています</span>
|
214
|
+
|
215
|
+
</div>
|
216
|
+
|
217
|
+
@endif
|
218
|
+
|
219
|
+
<div class="d-flex justify-content-end flex-grow-1">
|
220
|
+
|
221
|
+
@if(auth()->user()->isFollowing($user->id))
|
222
|
+
|
223
|
+
<form action="{{ route('unfollow', ['id' => $user->id]) }}" method="POST">
|
224
|
+
|
225
|
+
{{ csrf_field() }}
|
226
|
+
|
227
|
+
{{ method_field('DELETE') }}
|
228
|
+
|
229
|
+
<button type="submit" class="btn btn-danger">フォロー解除</button>
|
230
|
+
|
231
|
+
</form>
|
232
|
+
|
233
|
+
@else
|
234
|
+
|
235
|
+
<form action="{{ route('follow', ['id' =>
|
236
|
+
|
237
|
+
$user->id]) }}" method="POST">
|
238
|
+
|
239
|
+
{{ csrf_field() }}
|
240
|
+
|
241
|
+
<button type="submit" class="btn btn-primary">フォローする</button>
|
242
|
+
|
243
|
+
</form>
|
244
|
+
|
245
|
+
@endif
|
246
|
+
|
247
|
+
```
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
```route
|
252
|
+
|
253
|
+
Route::post('users/{id}/follow', 'UserController@follow')->name('follow');
|
254
|
+
|
255
|
+
Route::delete('users/{id}/unfollow', 'UserController@unfollow')->name('unfollow');
|
256
|
+
|
257
|
+
```
|
258
|
+
|
259
|
+
|
260
|
+
|
207
261
|
### 試したこと
|
208
262
|
|
209
263
|
User.phpのpublic function isFollowing(Int $user_id)のIntを?Intにしてみましたが、フォローやフォロー解除ができませんでした。
|
@@ -214,6 +268,10 @@
|
|
214
268
|
|
215
269
|
|
216
270
|
|
271
|
+
|
272
|
+
|
273
|
+
|
274
|
+
|
217
275
|
### 補足情報(FW/ツールのバージョンなど)
|
218
276
|
|
219
277
|
|