Angular.js 和 API 的错误访问控制允许来源 Laravel5.1

Error Access-Control-Allow-Origin With Angular.js and API with Laravel5.1

我正在使用 Laravel 5.1 和 Angular.js 开发应用程序,当我尝试连接时出现下一个错误:

XMLHttpRequest cannot load http://localhost:8000/university. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.

我在 angular 中有下一个代码:

angular.module('clientApp')

.controller('UniversityCtrl', function ($scope, $resource) {
  Universities = $resource("http://localhost:8000/university/:id",{id: "@id"});

  $scope.Universities = Universities.query();
});

我的看法:

<table>
 <thead>
   <tr>
     <th>University</th>
     <th>Address</th>
     <th>Phone</th>
   </tr>
</thead>

 <tbody>
   <tr ng-repeat="Universities in University">
      <td>{{University.name}}</td>
   </tr>
 </tbody>
</table>

和我的 Laravel 代码:

    public function index()
{
    $universities = university::all();
    return response()->json(
        $universities->toArray()
    );
}

谢谢 :D

单独安装此 package 作者:barryvdh