user

Jo Micheal

3 Aug 2022

API CORS error in Laravel 9x

Laravel

Hi, 
I am facing a CROS error when i try to access Laravel API using the browser, but it's working fine when I test the API using Postman or Thunder Client, any thoughts How can i avoid CORS error with Laravel?

Comments

Mohamed Atef

3 Aug 2022

Best Answer

best answer
githubgithubgithub

You can control CORS configuration from /config/cors.php, it suppose to look like this 

<?php

return [

 /*
 |--------------------------------------------------------------------------
 | Cross-Origin Resource Sharing (CORS) Configuration
 |--------------------------------------------------------------------------
 |
 | Here you may configure your settings for cross-origin resource sharing
 | or "CORS". This determines what cross-origin operations may execute
 | in web browsers. You are free to adjust these settings as needed.
 |
 | To learn more: //developer.mozilla.org/en-US/docs/Web/HTTP/CORS
 |
 */

 'paths' => ['api/*', 'sanctum/csrf-cookie'],

 'allowed_methods' => ['*'],

 'allowed_origins' => ['*'],

 'allowed_origins_patterns' => [],

 'allowed_headers' => ['*'],

 'exposed_headers' => [],

 'max_age' => 0,

 'supports_credentials' => false,

];

Make sure that the value of "allowed_origins" is * so it means Allow all 

Replies

Jo Micheal

3 Aug 2022

Thank you for your help

© 2024 Copyrights reserved for web-brackets.com