2024-07-20 13:28:38 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
|
|
use Illuminate\Http\Request;
|
2024-09-11 23:08:58 -04:00
|
|
|
use Illuminate\View\View;
|
2024-07-20 13:28:38 -04:00
|
|
|
|
|
|
|
class UserController extends Controller
|
|
|
|
{
|
|
|
|
use AuthorizesRequests;
|
|
|
|
|
2024-09-17 14:51:32 -04:00
|
|
|
public function show(Request $request, int $userId, string $username): View
|
2024-07-20 13:28:38 -04:00
|
|
|
{
|
2024-09-24 00:40:33 -04:00
|
|
|
$user = User::whereId($userId)
|
2024-10-05 14:09:22 -04:00
|
|
|
->with(['following', 'followers'])
|
2024-09-17 14:51:32 -04:00
|
|
|
->firstOrFail();
|
|
|
|
|
2024-09-24 00:40:33 -04:00
|
|
|
$mods = $user->mods()
|
2024-09-30 22:53:32 -04:00
|
|
|
->with([
|
|
|
|
'users',
|
|
|
|
'latestVersion',
|
|
|
|
'latestVersion.latestSptVersion',
|
|
|
|
])
|
2024-09-24 00:40:33 -04:00
|
|
|
->orderByDesc('created_at')
|
|
|
|
->paginate(10)
|
|
|
|
->fragment('mods');
|
|
|
|
|
2024-07-20 13:28:38 -04:00
|
|
|
if ($user->slug() !== $username) {
|
|
|
|
abort(404);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->user()?->cannot('view', $user)) {
|
|
|
|
abort(403);
|
|
|
|
}
|
|
|
|
|
2024-09-24 00:40:33 -04:00
|
|
|
return view('user.show', compact('user', 'mods'));
|
2024-07-20 13:28:38 -04:00
|
|
|
}
|
|
|
|
}
|