Laravel CORS | Access control allow origin issue Solution

Most of the cases while we use API in our code that means when getting data from another domain or website to our website, sometimes we face some errors CORS, Access control allow origin Block in Laravel or in the console that Cors blocked or Access-control-allow-origin in Laravel using Vuejs, Angularjs, jquery. Below steps for the problem solution or how to deal with this problem:

Problems:

Access to XMLHttpRequest at ” from origin ‘http://localhost’ has been blocked by CORS policy: Request header field x-requested-with is not allowed by Access-Control-Allow-Headers in preflight response.

Cross-Origin Read Blocking (CORB) blocked cross-origin response http://s3.amazonaws.com/jscriptcdn/1f546f49ebf4153c8a.js with MIME type application/xml. See https://www.chromestatus.com/feature/5629709824032768 for more details.

Solutions

  1. write on your terminal following line
  2. write on your terminal following line
  3. Go to your project_folder\app\Http\Kernel.php and check following is available or not in the protected $middleware = [ area

    For example my case

    if not added, then add \Fruitcake\Cors\HandleCors::class, line
  4. Go to your project_folder\config\cors.php and check following your file are exactly like mine

     
  5. Publish the config, for that write on your terminal following line:

     

    The official Package link for more info: https://packagist.org/packages/barryvdh/laravel-cors

Share with:


Comments are closed.