fix: resolve PHPStan static analysis warnings

This commit is contained in:
xboard
2025-05-07 19:48:19 +08:00
parent db235c10e8
commit 97e7ffccae
86 changed files with 2335 additions and 1206 deletions
+6 -7
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);
}
}