Laravel 请求资源上存在 'Access-Control-Allow-Origin' header 修复

Laravel Fix No 'Access-Control-Allow-Origin' header is present on the requested resource

如何解决

No 'Access-Control-Allow-Origin' header is present on the requested resource.

在 Laravel 7

我可以对回复做什么?

我已经试过了,但它不包括 header。

return response()->header('Access-Control-Allow-Origin','*')->json([
            'error'=>false,
        ]);

编辑 1

我已经添加了 FruitCakes Cors (https://github.com/fruitcake/laravel-cors)

我的 xhr 请求来自我在子域上托管的移动网站。

移动应用托管在 x.domain.com

laravel 应用托管在 domain.com

您可以使用这个包 - https://github.com/fruitcake/laravel-cors,它仍然适用于 Laravel 7,并且文档很容易理解。

另外,你为什么不更新到当前版本?这是教程 - https://laravel.com/docs/master/upgrade