XMLHttpRequest cannot load http: // localhost: 8000 / api / v1 / user / user_signin . It doesn’t give access to the requested resource. Origin ' http: // localhost ' is not allowed access.

I am making a post request from angular to laravel server. How to solve this problem?

  • this is just solved by adding the specified header to the server response - Grundy
  • I have about 50 unique links to api. How to add this heading to everyone at once? - J. Doe

2 answers 2

The answer from the author is, but still ..

More flexible ( and more complex ) solution: CORS in Laravel 5

Installation:

composer require barryvdh/laravel-cors 

Connection (in config/app.php , array of providers ):

 Barryvdh\Cors\ServiceProvider::class, 

Config publication:

 php artisan vendor:publish --provider="Barryvdh\Cors\ServiceProvider" // сюда: config/cors.php 

Using:

 Route::group(['middleware' => 'cors'], function(Router $router){ // маршруты }); 

    A link to the right solution was provided by @Grundy, for which he thanks a lot. There are different options, some work, others do not. Sending what works for me:

    In the file [bootstrap / app.php] add after <?php:

     // allow origin header('Access-Control-Allow-Origin: *'); // add any additional headers you need to support here header('Access-Control-Allow-Headers: Origin, Content-Type');