method() == 'OPTIONS') { return Response::create('', 'html', 204) ->header([ 'Access-Control-Allow-Origin' => '*', 'Access-Control-Allow-Methods' => 'GET, POST, PUT, DELETE, OPTIONS', 'Access-Control-Allow-Headers' => 'Origin, Content-Type, Accept, Authorization, X-Request-With, token', 'Access-Control-Allow-Credentials' => 'true', ]); } $response = $next($request); // 设置跨域响应头 $response->header([ 'Access-Control-Allow-Origin' => '*', 'Access-Control-Allow-Methods' => 'GET, POST, PUT, DELETE, OPTIONS', 'Access-Control-Allow-Headers' => 'Origin, Content-Type, Accept, Authorization, X-Request-With, token', 'Access-Control-Allow-Credentials' => 'true', ]); return $response; } }