forge/app/Http/Controllers/UserController.php
Refringe 80f3da13b9
Optimize User Follow Components
Much better, still not perfect. The mobile and the desktop components are being rendered twice, and each of their methods are running twice as well. Going to see if I can modify the structure to get away with only using one.
2024-10-05 14:09:22 -04:00

41 lines
958 B
PHP

<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Http\Request;
use Illuminate\View\View;
class UserController extends Controller
{
use AuthorizesRequests;
public function show(Request $request, int $userId, string $username): View
{
$user = User::whereId($userId)
->with(['following', 'followers'])
->firstOrFail();
$mods = $user->mods()
->with([
'users',
'latestVersion',
'latestVersion.latestSptVersion',
])
->orderByDesc('created_at')
->paginate(10)
->fragment('mods');
if ($user->slug() !== $username) {
abort(404);
}
if ($request->user()?->cannot('view', $user)) {
abort(403);
}
return view('user.show', compact('user', 'mods'));
}
}