fix: resolve PHPStan static analysis warnings

This commit is contained in:
xboard
2025-04-14 02:12:42 +08:00
parent 3d254c02c1
commit 2d3e4b4a95
84 changed files with 2330 additions and 1190 deletions

View File

@@ -5,6 +5,7 @@ namespace App\Http\Middleware;
use App\Exceptions\ApiException;
use Illuminate\Support\Facades\Auth;
use Closure;
use App\Models\User;
class Admin
{
@@ -17,15 +18,13 @@ class Admin
*/
public function handle($request, Closure $next)
{
if (!Auth::guard('sanctum')->check()) {
throw new ApiException('未登录或登陆已过期', 403);
}
/** @var User|null $user */
$user = Auth::guard('sanctum')->user();
if (!$user->is_admin) {
throw new ApiException('无管理员权限', 403);
if (!$user || !$user->is_admin) {
return response()->json(['message' => 'Unauthorized'], 403);
}
return $next($request);
}
}