慕妹3242003
下面的解决方案应该解决 Laravel 中与 CORS 相关的问题。Step1:创建一个新的中间件‘Php artisan make:middleware cors’第2步:把下面的放在创建的中间替换handle方法 public function handle($request, Closure $next) { return $next($request) ->header('Access-Control-Allow-Origin', '*') ->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS') ->header('Access-Control-Allow-Headers',' Origin, Content-Type, Accept, Authorization, X-Request-With') ->header('Access-Control-Allow-Credentials',' true');}第 3 步:然后转到 Kernel.php 文件并将其添加到应用程序的全局 HTTP 中间件堆栈下。ps 只添加了带有注释的最后一行,其他行之前存在。protected $middleware = [\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,\App\Http\Middleware\TrimStrings::class,\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,\App\Http\Middleware\TrustProxies::class,\App\Http\Middleware\Cors::class,//cors added here ];享受!