Here is what i tried
Middleware
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Credentials', 'true')
->header('Access-Control-Allow-Headers', 'Origin, Content-Type, Authorization, X-Requested-With, Accept, X-Token-Auth, Application')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
API route
Route::group(['middleware' => ['cors', 'auth:api']], function() {
Route::options('{any}');
Route::post('user/profile','UserController@profile');
Kernel.php
protected $routeMiddleware = [
'cors' => \App\Http\Middleware\Cors::class,
But still, I am getting this error in API call from another origin.
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Any reason?