If for some reason it's still not working.
First option for Laravel
The second option for any application
FIRST OPTION:
- As in the example above, we create middleware
php artisan make:middleware Cors
- Add the following code to
app/Http/Middleware/Cors.php
:
public function handle($request, Closure $next)
{
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS')
->header('Access-Control-Allow-Headers', 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range');
}
Look closely, the amount of data in the header ->header('Access-Control-Allow-Headers',
- Step three, add middleware to
$routeMiddleware
array in app/Http/Kernel.php
protected $routeMiddleware = [
....
'cors' => \App\Http\Middleware\Cors::class,
];
SECOND OPTION:
- Open the nginx.conf settings for your domain.
sudo nano /etc/nginx/sites-enabled/your-domain.conf
- Inside the server settings server
{ listen 80; .... }
please add the following code:
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';