I created an application in AngularJS and I'm trying to make calls to the Laravel API:
- MyApp (AngularJS): http://localhost:8080/
- API (Laravel Boilerplate): http://localhost:8000/
I use Laravel API Boilerplate (JWT Edition) to API.
But I get this error in the browser console:
XMLHttpRequest cannot load http://localhost:8000/api/auth/login. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
I tried to apply the cors middleware (barryvdh/laravel-cors) in api_routes.php but the error remains.
api_routes.php:
<?php
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', ['middleware' => 'cors'], function ($api) {
$api->post('auth/login', 'App\Api\V1\Controllers\AuthController@login');
$api->post('auth/signup', 'App\Api\V1\Controllers\AuthController@signup');
$api->post('auth/recovery', 'App\Api\V1\Controllers\AuthController@recovery');
$api->post('auth/reset', 'App\Api\V1\Controllers\AuthController@reset');
// example of protected route
$api->get('protected', ['middleware' => ['api.auth'], function () {
return \App\User::all();
}]);
// example of free route
$api->get('free', function() {
return \App\User::all();
});
});