header('Access-Control-Allow-Origin', '*'); $response->header('Access-Control-Allow-Headers', 'Origin, Content-Type, Cookie, X-CSRF-TOKEN, Accept, Authorization, X-XSRF-TOKEN'); $response->header('Access-Control-Expose-Headers', 'Authorization, authenticated'); $response->header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, OPTIONS'); $response->header('Access-Control-Allow-Credentials', 'true'); return $response; // // $response = $next($request); // if ($response instanceof Response) { // return $next($request)->header('Access-Control-Allow-Origin', '*') // ->header('Access-Control-Allow-Methods', 'GET,POST,PUT,OPTIONS,PATCH,DELETE,HEAD') // ->header('Access-Control-Allow-Headers', 'x-csrf-token,x-requested-with,content-type'); // ->header('Access-Control-Expose-Headers', 'Authorization, authenticated'); // ->header('Access-Control-Allow-Credentials', 'true'); // } // // 如果是实列 \Symfony\Component\HttpFoundation\Response::class // $response->headers->set('Access-Control-Allow-Origin', '*'); // $response->headers->set('Access-Control-Allow-Methods', 'GET,POST,PUT,OPTIONS,PATCH,DELETE,HEAD'); // $response->headers->set('Access-Control-Allow-Headers', 'x-csrf-token,x-requested-with,content-type'); // $response->headers->set('Access-Control-Expose-Headers', 'Authorization, authenticated'); // $response->headers->set('Access-Control-Allow-Credentials', 'true'); // return $response; } }