method() === 'OPTIONS') { $response = response(''); } else { $response = $handler($request); } // 添加 CORS 头 $response->withHeader('Access-Control-Allow-Origin', '*') ->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS') ->withHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization') ->withHeader('Access-Control-Max-Age', '86400'); return $response; } }