Laravel7跨域更新

Laravel7跨域更新

Laravel7跨域更新: 最近做企业微信项目使用Laravel框架开发,前端对接遇到跨域。 在Laravel7 以前都是写个跨域中间件即可解决跨域。 由于此项目使用Laravel7,且这个版本修改了跨域配置,搞半天还是跨域,最后看了下文档完美解决。 记录下,以免忘记了。


配置文件cors.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Cross-Origin Resource Sharing (CORS) Configuration
    |--------------------------------------------------------------------------
    |
    | Here you may configure your settings for cross-origin resource sharing
    | or "CORS". This determines what cross-origin operations may execute
    | in web browsers. You are free to adjust these settings as needed.
    |
    | To learn more: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
    |
    */

    'paths' => ['*']/*['api/*', 'sanctum/csrf-cookie','permission/*','settings/*']*/,  //*全部,也可以指定一些路由可跨域

    'allowed_methods' => ['*'],

    'allowed_origins' => ['*'],

    'allowed_origins_patterns' => [],

    'allowed_headers' => ['*'],

    'exposed_headers' => [],

    'max_age' => 0,

    'supports_credentials' => false,

];
猜你喜欢