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-11 23:08:58 -04:00
|
|
|
public function show(Request $request, User $user, string $username): View
|
2024-07-20 13:28:38 -04:00
|
|
|
{
|
|
|
|
if ($user->slug() !== $username) {
|
|
|
|
abort(404);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->user()?->cannot('view', $user)) {
|
|
|
|
abort(403);
|
|
|
|
}
|
|
|
|
|
2024-08-28 16:59:28 -04:00
|
|
|
// not sure if this is optimal. Some way to do $user->with(...) ???
|
|
|
|
$user = User::where('id', $user->id)
|
|
|
|
->with(['followers', 'following'])
|
|
|
|
->firstOrFail();
|
|
|
|
|
2024-07-20 13:28:38 -04:00
|
|
|
return view('user.show', compact('user'));
|
|
|
|
}
|
|
|
|
}
|