forge/app/Http/Controllers/UserController.php
2024-08-28 16:59:28 -04:00

31 lines
725 B
PHP

<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Http\Request;
class UserController extends Controller
{
use AuthorizesRequests;
public function show(Request $request, User $user, string $username)
{
if ($user->slug() !== $username) {
abort(404);
}
if ($request->user()?->cannot('view', $user)) {
abort(403);
}
// not sure if this is optimal. Some way to do $user->with(...) ???
$user = User::where('id', $user->id)
->with(['followers', 'following'])
->firstOrFail();
return view('user.show', compact('user'));
}
}