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

Get user location (city - country) from his IP address
Publish date: 2022-03-02 | Comments: 2
tymon/jwt-auth 0.5.12 requires illuminate/support ~5.0
Publish date: 2022-02-18 | Comments: 2
How can i pass data from blade template to vue component?
Publish date: 2022-02-11 | Comments: 1
Undefined Variable problem on Laravel 9.x
Publish date: 2022-03-06 | Comments: 3
How to check Laravel version?
Publish date: 2022-04-07 | Comments: 2