Framework integration CORS in Laravel version 9
P粉556159786
P粉556159786 2023-11-01 16:02:32
0
1
868

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?

P粉556159786
P粉556159786

reply all(1)
P粉176203781

Check if the CORS middleware exists in your app/Http/Kernel.php:

protected $middleware = [
    ...
    \Illuminate\Http\Middleware\HandleCors::class,
    ...
];

Then open your config/cors.php. It works exactly like fruitcake/laravel-cors:

 ['api/*', 'sanctum/csrf-cookie'],

    'allowed_methods' => ['*'],

    'allowed_origins' => ['*'],

    'allowed_origins_patterns' => [],

    'allowed_headers' => ['*'],

    'exposed_headers' => [],

    'max_age' => 0,

    'supports_credentials' => false,

];
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!