安装barryvdh/laravel-cors

composer require barryvdh/laravel-cors

全局配置

app.php

protected $middleware = [
    // ...
    \Barryvdh\Cors\HandleCors::class,
];

局部配置

protected $middlewareGroups = [
    'web' => [
       // ...
    ],
'api' => [
    // ...
    \Barryvdh\Cors\HandleCors::class,
],

];

将config/cors.php中的

'supportsCredentials' => true

改一下即可

其他设置google

https://packagist.org/packages/barryvdh/laravel-cors