laravel-cors
使用的laravel-cors
的作用是用于解决浏览器跨域的问题
在终端执行安装命令如下:
composer require barryvdh/laravel-cors
在Laravel配置文件app.php
的providers
数组中添加如下配置:
Barryvdh\Cors\ServiceProvider::class,
执行在终端执行发布配置文件命令如下:
php artisan vendor:publish --provider="Barryvdh\\Cors\\ServiceProvider"
执行后会在laravel目录下的config目录中新增cors.php
配置文件,如下图
至此laravel-Cors
安装完成。
详细信息:https://github.com/barryvdh/laravel-cors
To allow CORS for all your routes, add the HandleCors
middleware in the $middleware
property of app/Http/Kernel.php
class:
protected $middleware = [ // ... \Barryvdh\Cors\HandleCors::class,];
If you want to allow CORS on a specific middleware group or route, add the HandleCors
middleware to your group:
protected $middlewareGroups = [ 'web' => [ // ... ], 'api' => [ // ... \Barryvdh\Cors\HandleCors::class, ], ];
本文为wjw原创文章,转载无需和我联系,但请注明来自wjw博客http://wjiawen.cn
最新评论