user image

Jo Micheal
Published in : 2022-08-03

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 Date : 2022-08-03

Best answers

51

Best answers

51

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

<?phpreturn [ /* |-------------------------------------------------------------------------- | 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 

Jo Micheal Date : 2022-08-03

Thank you for your help

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

Laravel install passport have access denied error
Publish date: 2022-02-23 | Comments: 4
Undefined Variable problem on Laravel 9.x
Publish date: 2022-03-06 | Comments: 3
I want to make multiple foreign keys in Laravel, can I?
Publish date: 2022-01-27 | Comments: 5
How to check Laravel version?
Publish date: 2022-04-07 | Comments: 2
How to get original attribute value in Laravel?
Publish date: 2022-02-23 | Comments: 3
How can I use arabic words, paragraphs in the faker?
Publish date: 2022-03-06 | Comments: 1