I tried to use laravel-cors (https://github.com/barryvdh/laravel-cors) with Laravel 5.2 to update data, but I always get the same error:
XMLHttpRequest cannot load http://dev.pesanlab.com/api/v1/order/cart/add. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 500.
GET request works fine, but POST return error.
return [
'supportsCredentials' => false,
'allowedOrigins' => ['*'],
'allowedHeaders' => ['*'],
'allowedMethods' => ['GET', 'POST', 'PUT', 'DELETE'],
'exposedHeaders' => ['*'],
'maxAge' => 0,
'hosts' => [],
];
This is my code on Route.php
Route::group(['prefix' => 'api/v1'], function () {
Route::group(['middleware' => ['web', 'cors']], function () {
Route::post('order/cart/add','OrderController@cart_add');
});
});
Could you help me?
web
middleware and try again and let's see if that works or not. – The Alphaheader("Access-Control-Allow-Origin: *");
in yourpublic.index.php
and check if it works for now. – The Alpha