问题描述
如何解决
No 'Access-Control-Allow-Origin' header is present on the requested resource.
在 Laravel 7 上
我可以对回复做什么?
return response()->header('Access-Control-Allow-Origin','*')->json([
'error'=>false,]);
编辑 1
我已经添加了 FruitCakes Cors (https://github.com/fruitcake/laravel-cors)
我的 xhr 请求来自托管在子域上的移动网站。
托管在 x.domain.com 的移动应用
托管在 domain.com 的 laravel 应用
解决方法
你可以使用这个包 - https://github.com/fruitcake/laravel-cors,它仍然适用于 Laravel 7 并且文档很容易理解。
另外,你为什么不更新到当前版本?这是教程 - https://laravel.com/docs/master/upgrade