質問編集履歴
3
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -360,29 +360,31 @@
|
|
360
360
|
|
361
361
|
$follower->follow($user->id);
|
362
362
|
|
363
|
+
return back();
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
public function unfollow(User $user)
|
372
|
+
|
373
|
+
{
|
374
|
+
|
375
|
+
$follower = auth()->user();
|
376
|
+
|
377
|
+
$is_following = $follower->isFollowing($user->id);
|
378
|
+
|
379
|
+
if($is_following) {
|
380
|
+
|
381
|
+
$follower->unfollow($user->id);
|
382
|
+
|
383
|
+
return back();
|
384
|
+
|
363
385
|
}
|
364
386
|
|
365
|
-
|
387
|
+
|
366
|
-
|
367
|
-
}
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
public function unfollow(User $user)
|
372
|
-
|
373
|
-
{
|
374
|
-
|
375
|
-
$follower = auth()->user();
|
376
|
-
|
377
|
-
$is_following = $follower->isFollowing($user->id);
|
378
|
-
|
379
|
-
if($is_following) {
|
380
|
-
|
381
|
-
$follower->unfollow($user->id);
|
382
|
-
|
383
|
-
}
|
384
|
-
|
385
|
-
return back();
|
386
388
|
|
387
389
|
}
|
388
390
|
|
2
HTML(index.php)の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -402,288 +402,94 @@
|
|
402
402
|
|
403
403
|
```
|
404
404
|
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
use
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
class
|
428
|
-
|
429
|
-
{
|
430
|
-
|
431
|
-
/
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
/
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
}
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
/**
|
502
|
-
|
503
|
-
* Display the specified resource.
|
504
|
-
|
505
|
-
*
|
506
|
-
|
507
|
-
* @param int $id
|
508
|
-
|
509
|
-
* @return \Illuminate\Http\Response
|
510
|
-
|
511
|
-
*/
|
512
|
-
|
513
|
-
public function show(User $user, Tweet $tweet, Follower $follower)
|
514
|
-
|
515
|
-
{
|
516
|
-
|
517
|
-
$login_user = auth()->user();
|
518
|
-
|
519
|
-
$is_following = $login_user->isFollowing($user->id);
|
520
|
-
|
521
|
-
$is_followed = $login_user->isFollowed($user->id);
|
522
|
-
|
523
|
-
$timelines = $tweet->getUserTimeLine($user->id);
|
524
|
-
|
525
|
-
$tweet_count = $tweet->getTweetCount($user->id);
|
526
|
-
|
527
|
-
$follow_count = $follower->getFollowCount($user->id);
|
528
|
-
|
529
|
-
$follower_count = $follower->getFollowerCount($user->id);
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
return view('users.show', [
|
534
|
-
|
535
|
-
'user' => $user,
|
536
|
-
|
537
|
-
'is_following' => $is_following,
|
538
|
-
|
539
|
-
'is_followed' => $is_followed,
|
540
|
-
|
541
|
-
'timelines' => $timelines,
|
542
|
-
|
543
|
-
'tweet_count' => $tweet_count,
|
544
|
-
|
545
|
-
'follow_count' => $follow_count,
|
546
|
-
|
547
|
-
'follower_count' => $follower_count
|
548
|
-
|
549
|
-
]);
|
550
|
-
|
551
|
-
}
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
/**
|
556
|
-
|
557
|
-
* Show the form for editing the specified resource.
|
558
|
-
|
559
|
-
*
|
560
|
-
|
561
|
-
* @param int $id
|
562
|
-
|
563
|
-
* @return \Illuminate\Http\Response
|
564
|
-
|
565
|
-
*/
|
566
|
-
|
567
|
-
public function edit(User $user)
|
568
|
-
|
569
|
-
{
|
570
|
-
|
571
|
-
return view('users.edit', ['user' => $user]);
|
572
|
-
|
573
|
-
}
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
/**
|
578
|
-
|
579
|
-
* Update the specified resource in storage.
|
580
|
-
|
581
|
-
*
|
582
|
-
|
583
|
-
* @param \Illuminate\Http\Request $request
|
584
|
-
|
585
|
-
* @param int $id
|
586
|
-
|
587
|
-
* @return \Illuminate\Http\Response
|
588
|
-
|
589
|
-
*/
|
590
|
-
|
591
|
-
public function update(Request $request, User $user)
|
592
|
-
|
593
|
-
{
|
594
|
-
|
595
|
-
$data = $request->all();
|
596
|
-
|
597
|
-
$validator = Validator::make($data, [
|
598
|
-
|
599
|
-
'screen_name' => ['required', 'string', 'max:50', Rule::unique('users')->ignore($user->id)],
|
600
|
-
|
601
|
-
'name' => ['required', 'string', 'max:255'],
|
602
|
-
|
603
|
-
'profile_image' => ['file', 'image', 'mimes:jpeg,png,jpg', 'max:2048'],
|
604
|
-
|
605
|
-
'email' => ['required', 'string', 'email', 'max:255', Rule::unique('users')->ignore($user->id)]
|
606
|
-
|
607
|
-
]);
|
608
|
-
|
609
|
-
$validator->validate();
|
610
|
-
|
611
|
-
$user->updateProfile($data);
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
return redirect('users/'.$user->id);
|
616
|
-
|
617
|
-
}
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
/**
|
622
|
-
|
623
|
-
* Remove the specified resource from storage.
|
624
|
-
|
625
|
-
*
|
626
|
-
|
627
|
-
* @param int $id
|
628
|
-
|
629
|
-
* @return \Illuminate\Http\Response
|
630
|
-
|
631
|
-
*/
|
632
|
-
|
633
|
-
public function destroy($id)
|
634
|
-
|
635
|
-
{
|
636
|
-
|
637
|
-
//
|
638
|
-
|
639
|
-
}
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
public function follow(User $user)
|
644
|
-
|
645
|
-
{
|
646
|
-
|
647
|
-
$follower = auth()->user();
|
648
|
-
|
649
|
-
$is_following = $follower->isFollowing($user->id);
|
650
|
-
|
651
|
-
if(!$is_following) {
|
652
|
-
|
653
|
-
$follower->follow($user->id);
|
654
|
-
|
655
|
-
}
|
656
|
-
|
657
|
-
return back();
|
658
|
-
|
659
|
-
}
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
public function unfollow(User $user)
|
664
|
-
|
665
|
-
{
|
666
|
-
|
667
|
-
$follower = auth()->user();
|
668
|
-
|
669
|
-
$is_following = $follower->isFollowing($user->id);
|
670
|
-
|
671
|
-
if($is_following) {
|
672
|
-
|
673
|
-
$follower->unfollow($user->id);
|
674
|
-
|
675
|
-
}
|
676
|
-
|
677
|
-
return back();
|
678
|
-
|
679
|
-
}
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
}
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
```
|
405
|
+
@extends('layouts.app')
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
@section('content')
|
410
|
+
|
411
|
+
<div class="container">
|
412
|
+
|
413
|
+
<div class="row justify-content-center">
|
414
|
+
|
415
|
+
<div class="col-md-8">
|
416
|
+
|
417
|
+
@foreach ($all_users as $user)
|
418
|
+
|
419
|
+
<div class="card">
|
420
|
+
|
421
|
+
<div class="card-haeder p-3 w-100 d-flex">
|
422
|
+
|
423
|
+
<img src="{{ asset('storage/profile_image/' .$user->profile_image) }}" class="rounded-circle" width="50" height="50">
|
424
|
+
|
425
|
+
<div class="ml-2 d-flex flex-column">
|
426
|
+
|
427
|
+
<p class="mb-0">{{ $user->name }}</p>
|
428
|
+
|
429
|
+
<a href="{{ url('users/' .$user->id) }}" class="text-secondary">{{ $user->screen_name }}</a>
|
430
|
+
|
431
|
+
</div>
|
432
|
+
|
433
|
+
@if (auth()->user()->isFollowed($user->id))
|
434
|
+
|
435
|
+
<div class="px-2">
|
436
|
+
|
437
|
+
<span class="px-1 bg-secondary text-light">フォローされています</span>
|
438
|
+
|
439
|
+
</div>
|
440
|
+
|
441
|
+
@endif
|
442
|
+
|
443
|
+
<div class="d-flex justify-content-end flex-grow-1">
|
444
|
+
|
445
|
+
@if (auth()->user()->isFollowing($user->id))
|
446
|
+
|
447
|
+
<form action="{{ route('unfollow', ['id' => $user->id]) }}" method="post">
|
448
|
+
|
449
|
+
{{ csrf_field() }}
|
450
|
+
|
451
|
+
{{ method_field('DELETE') }}
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
<button type="submit" class="btn btn-danger">フォロー解除</button>
|
456
|
+
|
457
|
+
</form>
|
458
|
+
|
459
|
+
@else
|
460
|
+
|
461
|
+
<form action="{{ route('follow', ['id' => $user->id]) }}" method="post">
|
462
|
+
|
463
|
+
{{ csrf_field() }}
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
<button type="submit" class="btn btn-primary">フォローする</button>
|
468
|
+
|
469
|
+
</form>
|
470
|
+
|
471
|
+
@endif
|
472
|
+
|
473
|
+
</div>
|
474
|
+
|
475
|
+
</div>
|
476
|
+
|
477
|
+
</div>
|
478
|
+
|
479
|
+
@endforeach
|
480
|
+
|
481
|
+
</div>
|
482
|
+
|
483
|
+
</div>
|
484
|
+
|
485
|
+
<div class="my-4 d-flex justify-content-center">
|
486
|
+
|
487
|
+
{{ $all_users->links() }}
|
488
|
+
|
489
|
+
</div>
|
490
|
+
|
491
|
+
</div>
|
492
|
+
|
493
|
+
@endsection
|
494
|
+
|
495
|
+
```
|
1
コードの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -31,3 +31,659 @@
|
|
31
31
|
|
32
32
|
|
33
33
|
よろしくお願いいたします。
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
web.php
|
38
|
+
|
39
|
+
```
|
40
|
+
|
41
|
+
<?php
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
/*
|
46
|
+
|
47
|
+
|--------------------------------------------------------------------------
|
48
|
+
|
49
|
+
| Web Routes
|
50
|
+
|
51
|
+
|--------------------------------------------------------------------------
|
52
|
+
|
53
|
+
|
|
54
|
+
|
55
|
+
| Here is where you can register web routes for your application. These
|
56
|
+
|
57
|
+
| routes are loaded by the RouteServiceProvider within a group which
|
58
|
+
|
59
|
+
| contains the "web" middleware group. Now create something great!
|
60
|
+
|
61
|
+
|
|
62
|
+
|
63
|
+
*/
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
Route::get('/', function () {
|
68
|
+
|
69
|
+
return view('welcome');
|
70
|
+
|
71
|
+
});
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
Auth::routes();
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
Route::get('/home', 'HomeController@index')->name('home');
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
Route::group(['middleware' => 'auth'], function() {
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
// ユーザ関連
|
88
|
+
|
89
|
+
Route::resource('users', 'UsersController', ['only' => ['index', 'show', 'edit', 'update']]);
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
// フォロー/フォロー解除を追加
|
94
|
+
|
95
|
+
Route::post('users/{user}/follow', 'UsersController@follow')->name('follow');
|
96
|
+
|
97
|
+
Route::delete('users/{user}/unfollow', 'UsersController@unfollow')->name('unfollow');
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
});
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
```
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
UsersController.php
|
110
|
+
|
111
|
+
```
|
112
|
+
|
113
|
+
<?php
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
namespace App\Http\Controllers;
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
use Illuminate\Http\Request;
|
122
|
+
|
123
|
+
use Illuminate\Support\Facades\Validator;
|
124
|
+
|
125
|
+
use Illuminate\Validation\Rule;
|
126
|
+
|
127
|
+
use App\Models\User;
|
128
|
+
|
129
|
+
use App\Models\Tweet;
|
130
|
+
|
131
|
+
use App\Models\Follower;
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
class UsersController extends Controller
|
136
|
+
|
137
|
+
{
|
138
|
+
|
139
|
+
/**
|
140
|
+
|
141
|
+
* Display a listing of the resource.
|
142
|
+
|
143
|
+
*
|
144
|
+
|
145
|
+
* @return \Illuminate\Http\Response
|
146
|
+
|
147
|
+
*/
|
148
|
+
|
149
|
+
public function index(User $user)
|
150
|
+
|
151
|
+
{
|
152
|
+
|
153
|
+
$all_users = $user->getAllUsers(auth()->user()->id);
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
return view('users.index', [
|
158
|
+
|
159
|
+
'all_users' => $all_users
|
160
|
+
|
161
|
+
]);
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
/**
|
168
|
+
|
169
|
+
* Show the form for creating a new resource.
|
170
|
+
|
171
|
+
*
|
172
|
+
|
173
|
+
* @return \Illuminate\Http\Response
|
174
|
+
|
175
|
+
*/
|
176
|
+
|
177
|
+
public function create()
|
178
|
+
|
179
|
+
{
|
180
|
+
|
181
|
+
//
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
/**
|
188
|
+
|
189
|
+
* Store a newly created resource in storage.
|
190
|
+
|
191
|
+
*
|
192
|
+
|
193
|
+
* @param \Illuminate\Http\Request $request
|
194
|
+
|
195
|
+
* @return \Illuminate\Http\Response
|
196
|
+
|
197
|
+
*/
|
198
|
+
|
199
|
+
public function store(Request $request)
|
200
|
+
|
201
|
+
{
|
202
|
+
|
203
|
+
//
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
/**
|
210
|
+
|
211
|
+
* Display the specified resource.
|
212
|
+
|
213
|
+
*
|
214
|
+
|
215
|
+
* @param int $id
|
216
|
+
|
217
|
+
* @return \Illuminate\Http\Response
|
218
|
+
|
219
|
+
*/
|
220
|
+
|
221
|
+
public function show(User $user, Tweet $tweet, Follower $follower)
|
222
|
+
|
223
|
+
{
|
224
|
+
|
225
|
+
$login_user = auth()->user();
|
226
|
+
|
227
|
+
$is_following = $login_user->isFollowing($user->id);
|
228
|
+
|
229
|
+
$is_followed = $login_user->isFollowed($user->id);
|
230
|
+
|
231
|
+
$timelines = $tweet->getUserTimeLine($user->id);
|
232
|
+
|
233
|
+
$tweet_count = $tweet->getTweetCount($user->id);
|
234
|
+
|
235
|
+
$follow_count = $follower->getFollowCount($user->id);
|
236
|
+
|
237
|
+
$follower_count = $follower->getFollowerCount($user->id);
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
return view('users.show', [
|
242
|
+
|
243
|
+
'user' => $user,
|
244
|
+
|
245
|
+
'is_following' => $is_following,
|
246
|
+
|
247
|
+
'is_followed' => $is_followed,
|
248
|
+
|
249
|
+
'timelines' => $timelines,
|
250
|
+
|
251
|
+
'tweet_count' => $tweet_count,
|
252
|
+
|
253
|
+
'follow_count' => $follow_count,
|
254
|
+
|
255
|
+
'follower_count' => $follower_count
|
256
|
+
|
257
|
+
]);
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
/**
|
264
|
+
|
265
|
+
* Show the form for editing the specified resource.
|
266
|
+
|
267
|
+
*
|
268
|
+
|
269
|
+
* @param int $id
|
270
|
+
|
271
|
+
* @return \Illuminate\Http\Response
|
272
|
+
|
273
|
+
*/
|
274
|
+
|
275
|
+
public function edit(User $user)
|
276
|
+
|
277
|
+
{
|
278
|
+
|
279
|
+
return view('users.edit', ['user' => $user]);
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
/**
|
286
|
+
|
287
|
+
* Update the specified resource in storage.
|
288
|
+
|
289
|
+
*
|
290
|
+
|
291
|
+
* @param \Illuminate\Http\Request $request
|
292
|
+
|
293
|
+
* @param int $id
|
294
|
+
|
295
|
+
* @return \Illuminate\Http\Response
|
296
|
+
|
297
|
+
*/
|
298
|
+
|
299
|
+
public function update(Request $request, User $user)
|
300
|
+
|
301
|
+
{
|
302
|
+
|
303
|
+
$data = $request->all();
|
304
|
+
|
305
|
+
$validator = Validator::make($data, [
|
306
|
+
|
307
|
+
'screen_name' => ['required', 'string', 'max:50', Rule::unique('users')->ignore($user->id)],
|
308
|
+
|
309
|
+
'name' => ['required', 'string', 'max:255'],
|
310
|
+
|
311
|
+
'profile_image' => ['file', 'image', 'mimes:jpeg,png,jpg', 'max:2048'],
|
312
|
+
|
313
|
+
'email' => ['required', 'string', 'email', 'max:255', Rule::unique('users')->ignore($user->id)]
|
314
|
+
|
315
|
+
]);
|
316
|
+
|
317
|
+
$validator->validate();
|
318
|
+
|
319
|
+
$user->updateProfile($data);
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
return redirect('users/'.$user->id);
|
324
|
+
|
325
|
+
}
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
/**
|
330
|
+
|
331
|
+
* Remove the specified resource from storage.
|
332
|
+
|
333
|
+
*
|
334
|
+
|
335
|
+
* @param int $id
|
336
|
+
|
337
|
+
* @return \Illuminate\Http\Response
|
338
|
+
|
339
|
+
*/
|
340
|
+
|
341
|
+
public function destroy($id)
|
342
|
+
|
343
|
+
{
|
344
|
+
|
345
|
+
//
|
346
|
+
|
347
|
+
}
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
public function follow(User $user)
|
352
|
+
|
353
|
+
{
|
354
|
+
|
355
|
+
$follower = auth()->user();
|
356
|
+
|
357
|
+
$is_following = $follower->isFollowing($user->id);
|
358
|
+
|
359
|
+
if(!$is_following) {
|
360
|
+
|
361
|
+
$follower->follow($user->id);
|
362
|
+
|
363
|
+
}
|
364
|
+
|
365
|
+
return back();
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
public function unfollow(User $user)
|
372
|
+
|
373
|
+
{
|
374
|
+
|
375
|
+
$follower = auth()->user();
|
376
|
+
|
377
|
+
$is_following = $follower->isFollowing($user->id);
|
378
|
+
|
379
|
+
if($is_following) {
|
380
|
+
|
381
|
+
$follower->unfollow($user->id);
|
382
|
+
|
383
|
+
}
|
384
|
+
|
385
|
+
return back();
|
386
|
+
|
387
|
+
}
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
}
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
```
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
index.php
|
402
|
+
|
403
|
+
```
|
404
|
+
|
405
|
+
<?php
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
namespace App\Http\Controllers;
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
use Illuminate\Http\Request;
|
414
|
+
|
415
|
+
use Illuminate\Support\Facades\Validator;
|
416
|
+
|
417
|
+
use Illuminate\Validation\Rule;
|
418
|
+
|
419
|
+
use App\Models\User;
|
420
|
+
|
421
|
+
use App\Models\Tweet;
|
422
|
+
|
423
|
+
use App\Models\Follower;
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
class UsersController extends Controller
|
428
|
+
|
429
|
+
{
|
430
|
+
|
431
|
+
/**
|
432
|
+
|
433
|
+
* Display a listing of the resource.
|
434
|
+
|
435
|
+
*
|
436
|
+
|
437
|
+
* @return \Illuminate\Http\Response
|
438
|
+
|
439
|
+
*/
|
440
|
+
|
441
|
+
public function index(User $user)
|
442
|
+
|
443
|
+
{
|
444
|
+
|
445
|
+
$all_users = $user->getAllUsers(auth()->user()->id);
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
return view('users.index', [
|
450
|
+
|
451
|
+
'all_users' => $all_users
|
452
|
+
|
453
|
+
]);
|
454
|
+
|
455
|
+
}
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
/**
|
460
|
+
|
461
|
+
* Show the form for creating a new resource.
|
462
|
+
|
463
|
+
*
|
464
|
+
|
465
|
+
* @return \Illuminate\Http\Response
|
466
|
+
|
467
|
+
*/
|
468
|
+
|
469
|
+
public function create()
|
470
|
+
|
471
|
+
{
|
472
|
+
|
473
|
+
//
|
474
|
+
|
475
|
+
}
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
/**
|
480
|
+
|
481
|
+
* Store a newly created resource in storage.
|
482
|
+
|
483
|
+
*
|
484
|
+
|
485
|
+
* @param \Illuminate\Http\Request $request
|
486
|
+
|
487
|
+
* @return \Illuminate\Http\Response
|
488
|
+
|
489
|
+
*/
|
490
|
+
|
491
|
+
public function store(Request $request)
|
492
|
+
|
493
|
+
{
|
494
|
+
|
495
|
+
//
|
496
|
+
|
497
|
+
}
|
498
|
+
|
499
|
+
|
500
|
+
|
501
|
+
/**
|
502
|
+
|
503
|
+
* Display the specified resource.
|
504
|
+
|
505
|
+
*
|
506
|
+
|
507
|
+
* @param int $id
|
508
|
+
|
509
|
+
* @return \Illuminate\Http\Response
|
510
|
+
|
511
|
+
*/
|
512
|
+
|
513
|
+
public function show(User $user, Tweet $tweet, Follower $follower)
|
514
|
+
|
515
|
+
{
|
516
|
+
|
517
|
+
$login_user = auth()->user();
|
518
|
+
|
519
|
+
$is_following = $login_user->isFollowing($user->id);
|
520
|
+
|
521
|
+
$is_followed = $login_user->isFollowed($user->id);
|
522
|
+
|
523
|
+
$timelines = $tweet->getUserTimeLine($user->id);
|
524
|
+
|
525
|
+
$tweet_count = $tweet->getTweetCount($user->id);
|
526
|
+
|
527
|
+
$follow_count = $follower->getFollowCount($user->id);
|
528
|
+
|
529
|
+
$follower_count = $follower->getFollowerCount($user->id);
|
530
|
+
|
531
|
+
|
532
|
+
|
533
|
+
return view('users.show', [
|
534
|
+
|
535
|
+
'user' => $user,
|
536
|
+
|
537
|
+
'is_following' => $is_following,
|
538
|
+
|
539
|
+
'is_followed' => $is_followed,
|
540
|
+
|
541
|
+
'timelines' => $timelines,
|
542
|
+
|
543
|
+
'tweet_count' => $tweet_count,
|
544
|
+
|
545
|
+
'follow_count' => $follow_count,
|
546
|
+
|
547
|
+
'follower_count' => $follower_count
|
548
|
+
|
549
|
+
]);
|
550
|
+
|
551
|
+
}
|
552
|
+
|
553
|
+
|
554
|
+
|
555
|
+
/**
|
556
|
+
|
557
|
+
* Show the form for editing the specified resource.
|
558
|
+
|
559
|
+
*
|
560
|
+
|
561
|
+
* @param int $id
|
562
|
+
|
563
|
+
* @return \Illuminate\Http\Response
|
564
|
+
|
565
|
+
*/
|
566
|
+
|
567
|
+
public function edit(User $user)
|
568
|
+
|
569
|
+
{
|
570
|
+
|
571
|
+
return view('users.edit', ['user' => $user]);
|
572
|
+
|
573
|
+
}
|
574
|
+
|
575
|
+
|
576
|
+
|
577
|
+
/**
|
578
|
+
|
579
|
+
* Update the specified resource in storage.
|
580
|
+
|
581
|
+
*
|
582
|
+
|
583
|
+
* @param \Illuminate\Http\Request $request
|
584
|
+
|
585
|
+
* @param int $id
|
586
|
+
|
587
|
+
* @return \Illuminate\Http\Response
|
588
|
+
|
589
|
+
*/
|
590
|
+
|
591
|
+
public function update(Request $request, User $user)
|
592
|
+
|
593
|
+
{
|
594
|
+
|
595
|
+
$data = $request->all();
|
596
|
+
|
597
|
+
$validator = Validator::make($data, [
|
598
|
+
|
599
|
+
'screen_name' => ['required', 'string', 'max:50', Rule::unique('users')->ignore($user->id)],
|
600
|
+
|
601
|
+
'name' => ['required', 'string', 'max:255'],
|
602
|
+
|
603
|
+
'profile_image' => ['file', 'image', 'mimes:jpeg,png,jpg', 'max:2048'],
|
604
|
+
|
605
|
+
'email' => ['required', 'string', 'email', 'max:255', Rule::unique('users')->ignore($user->id)]
|
606
|
+
|
607
|
+
]);
|
608
|
+
|
609
|
+
$validator->validate();
|
610
|
+
|
611
|
+
$user->updateProfile($data);
|
612
|
+
|
613
|
+
|
614
|
+
|
615
|
+
return redirect('users/'.$user->id);
|
616
|
+
|
617
|
+
}
|
618
|
+
|
619
|
+
|
620
|
+
|
621
|
+
/**
|
622
|
+
|
623
|
+
* Remove the specified resource from storage.
|
624
|
+
|
625
|
+
*
|
626
|
+
|
627
|
+
* @param int $id
|
628
|
+
|
629
|
+
* @return \Illuminate\Http\Response
|
630
|
+
|
631
|
+
*/
|
632
|
+
|
633
|
+
public function destroy($id)
|
634
|
+
|
635
|
+
{
|
636
|
+
|
637
|
+
//
|
638
|
+
|
639
|
+
}
|
640
|
+
|
641
|
+
|
642
|
+
|
643
|
+
public function follow(User $user)
|
644
|
+
|
645
|
+
{
|
646
|
+
|
647
|
+
$follower = auth()->user();
|
648
|
+
|
649
|
+
$is_following = $follower->isFollowing($user->id);
|
650
|
+
|
651
|
+
if(!$is_following) {
|
652
|
+
|
653
|
+
$follower->follow($user->id);
|
654
|
+
|
655
|
+
}
|
656
|
+
|
657
|
+
return back();
|
658
|
+
|
659
|
+
}
|
660
|
+
|
661
|
+
|
662
|
+
|
663
|
+
public function unfollow(User $user)
|
664
|
+
|
665
|
+
{
|
666
|
+
|
667
|
+
$follower = auth()->user();
|
668
|
+
|
669
|
+
$is_following = $follower->isFollowing($user->id);
|
670
|
+
|
671
|
+
if($is_following) {
|
672
|
+
|
673
|
+
$follower->unfollow($user->id);
|
674
|
+
|
675
|
+
}
|
676
|
+
|
677
|
+
return back();
|
678
|
+
|
679
|
+
}
|
680
|
+
|
681
|
+
|
682
|
+
|
683
|
+
|
684
|
+
|
685
|
+
}
|
686
|
+
|
687
|
+
|
688
|
+
|
689
|
+
```
|