Good morning! I'm developing a hybrid application using ionic, when I try to send a post to my server (laravel) the error below occurs:
XMLHttpRequest can not load link . In 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' link ' is therefore not allowed access.
Here is my service that contains the URL:
angular.module('starter.services')
.factory('Order', ['$resource', 'appConfig',function($resource, appConfig) {
return $resource(appConfig.baseUrl + '/api/client/order/:id', {id: '@id'},{
query: {
isArray: false
}
});
}]);
The cors is activated in laravel, it follows my routes where it contains the URL:
Route::group(['middleware' => 'cors'], function(){
Route::post('oauth/access_token', function() {
return Response::json(Authorizer::issueAccessToken());
});
Route::group(['prefix'=>'api', 'middleware'=>'oauth','as'=>'api.'], function(){
Route::group(['prefix'=>'client','middleware'=>'oauth.checkrole:client','as'=>'client.'], function(){
Route::resource('order',
'Api\Client\ClientCheckoutController', [
'except' => ['create', 'edit', 'destroy']
]);
Route::get('products','Api\Client\ClientProductController@index');
});
});
Following file cors.php:
<?php
return [
/*
|--------------------------------------------------------------------------
| Laravel CORS
|--------------------------------------------------------------------------
|
| allowedOrigins, allowedHeaders and allowedMethods can be set to array('*')
| to accept any value.
|
*/
'supportsCredentials' => false,
'allowedOrigins' => ['*'],
'allowedHeaders' => ['*'],
'allowedMethods' => ['GET', 'POST', 'PUT', 'DELETE'],
'exposedHeaders' => [],
'maxAge' => 0,
'hosts' => [],
];
Thank you guys.