When the error occurred before Laravel 9:
Access to XMLHttpRequest at 'http://localhost:8000/demo' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I had to install fruitcake/laravel-cors (https://www.positronx.io/how-to-enable-cors-in-laravel/).
In Laravel 9 I found the information:
"Integrate Laravel CORS into the framework Dries Vints migrated the Fruitcake/laravel-cors package into the Laravel framework: The main reason is that we want to eliminate the circular dependency we depend on, in addition to eliminating another dependency of the skeleton. All credit for the code goes to @barryvdh of @fruitcake. Thank you for your long-term maintenance of this package! ”.
How to create cors for url: api/list and api/profiles in new Laravel?
Check if the CORS middleware exists in your
app/Http/Kernel.php
:Then open your
config/cors.php
. It works exactly likefruitcake/laravel-cors
: