Laravel 跨域问题解决

630 阅读1分钟

安装 barryvdh/laravel-cors 包

1.composer require barryvdh/laravel-cors

2.在 config/app.php provides array 添加 Barryvdh\Cors\ServiceProvider::class,

全局引用

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

Group middleware 引用

protected $middlewareGroups = [
    'web' => [
       // ...
    ],

    'api' => [
        // ...
        \Barryvdh\Cors\HandleCors::class,
    ],
];

具体参考

CORS Middleware for Laravel 5