-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathProfileController.php
53 lines (44 loc) · 1.34 KB
/
ProfileController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
declare(strict_types=1);
namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use App\Models\Article;
use App\Models\Discussion;
use App\Models\Thread;
use App\Models\User;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
final class ProfileController extends Controller
{
public function show(Request $request, ?User $user = null): View|RedirectResponse
{
if ($user) {
$articles = Article::with('tags')
->whereBelongsTo($user)
->published()
->recent()
->limit(5)
->get();
$threads = Thread::whereBelongsTo($user)
->orderByDesc('created_at')
->limit(5)
->get();
$discussions = Discussion::with('tags')
->whereBelongsTo($user)
->limit(5)
->get();
return view('user.profile', [
'user' => $user,
'articles' => $articles,
'threads' => $threads,
'discussions' => $discussions,
'activities' => [],
]);
}
if ($request->user()) {
return redirect()->route('profile', $request->user()->username);
}
abort(404);
}
}