在 Laravel 中不允许“访问控制允许原点”标头


Allow No 'Access-Control-Allow-Origin' header in Laravel

如何允许拉拉维尔No 'Access-Control-Allow-Origin' header is present on the requested?因为当我尝试使用 angular $http.get()某个 url 时.js我总是收到错误。

哦,知道了。我只需要在我的应用程序过滤之前添加。

过滤器.php

App::before(function($request)
{
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
    header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Requested-With');
    header('Access-Control-Allow-Credentials: true');
});