Laravel CORS settings have no effect: missing config/cors.php, paths and cache
has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resourceShort answer
Laravel answers CORS preflights itself through the HandleCors middleware, but only for URLs listed in the paths option of config/cors.php. That file is not published by default. Publish it, add your route pattern, set supports_credentials for cookie logins, and clear the config cache.
Fix it fast
1Find out which cause you have
Send the preflight to the exact URL the frontend calls and look at the response headers. No Access-Control headers means Laravel is not applying CORS to that path.
curl -s -o /dev/null -D - -X OPTIONS http://localhost:8000/api/user \ -H "Origin: http://localhost:5173" \ -H "Access-Control-Request-Method: GET"2Match what you see, then jump to its fix
- 1
The preflight for /api/... works but a route outside api/* returns no CORS headers.The route path is not covered by the paths optionFix - 2
You edited a CORS setting, but the config:show output and the headers are unchanged.config/cors.php was never published, or the config is cachedFix - 3
Firefox reports: Credential is not supported if the CORS header 'Access-Control-Allow-Origin' is '*', or the login call is blocked.Cookie login from an SPA while supports_credentials is falseFix - 4
The request returns 404 and routes/api.php does not exist in a new Laravel 11 or later app.The project has no API routes yetFix
- 1
What does the error look like?
has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resourceResponse to preflight request doesn't pass access control checkCredential is not supported if the CORS header 'Access-Control-Allow-Origin' is '*'
Cause 1 of 4
The route path is not covered by the paths option
1Check
The default cors configuration lists paths as api/* and sanctum/csrf-cookie only. A route such as /login or /graphql gets no CORS headers.
php artisan config:show cors2Fix
Publish the file, then add your path pattern to paths.
php artisan config:publish cors
// config/cors.php
'paths' => ['api/*', 'sanctum/csrf-cookie', 'login', 'logout'],3Verify
The preflight now returns Access-Control-Allow-Origin.
curl -s -o /dev/null -D - -X OPTIONS http://localhost:8000/login \
-H "Origin: http://localhost:5173" -H "Access-Control-Request-Method: POST" | grep -i "^access-control"Confirmed by raw.githubusercontent.com
Cause 2 of 4
config/cors.php was never published, or the config is cached
1Check
In current Laravel, cors.php is not published by default. Also, when configuration is cached, edits and .env changes are not read until the cache is rebuilt.
ls config/cors.php; php artisan config:show cors2Fix
Publish the file if it is missing, then clear the configuration cache, and rebuild it on production after your change.
php artisan config:publish cors
php artisan config:clear
# production, after deploying
php artisan config:cache3Verify
php artisan config:show cors prints your edited values.
php artisan config:show corsConfirmed by laravel.com
Cause 3 of 4
Cookie login from an SPA while supports_credentials is false
1Check
Sanctum's SPA login needs the response header Access-Control-Allow-Credentials: True. The default supports_credentials value is false, and a wildcard origin cannot be used with credentials.
grep -n "supports_credentials\|allowed_origins" config/cors.php2Fix
Set supports_credentials to true, list the SPA origin explicitly, and enable withCredentials and withXSRFToken on the HTTP client.
// config/cors.php
'allowed_origins' => ['http://localhost:5173'],
'supports_credentials' => true,
// resources/js/bootstrap.js (axios)
axios.defaults.withCredentials = true;
axios.defaults.withXSRFToken = true;3Verify
The preflight shows Access-Control-Allow-Credentials: true and the exact origin.
curl -s -o /dev/null -D - -X OPTIONS http://localhost:8000/sanctum/csrf-cookie \
-H "Origin: http://localhost:5173" -H "Access-Control-Request-Method: GET" | grep -i "^access-control"Confirmed by laravel.com
Cause 4 of 4
The project has no API routes yet
1Check
New Laravel applications since version 11 do not ship API routing by default. Without it the api/* paths do not exist, so there is nothing for CORS to apply to.
ls routes; php artisan route:list --path=api2Fix
Install API routing, which also installs Sanctum.
php artisan install:api3Verify
routes/api.php exists and route:list shows your api routes.
php artisan route:list --path=apiConfirmed by laravel.com
How do I stop it coming back?
- Commit config/cors.php so the allowed origins are reviewed like code.
- Run config:clear locally whenever a setting seems to be ignored.
- Never combine a wildcard origin with credentials.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- Spotless LaundryAn on-demand laundry app: Flutter on a Laravel back end, with Firebase for live updates.
- EZ EstimaterConstruction quoting and job tracking for contractors, on a Laravel and Firebase stack.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
The browser blocks your API response: no Access-Control-Allow-Origin header
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.example.com/orders. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
The browser received the response but refused to hand it to your script, because it did not carry an Access-Control-Allow-Origin header naming the page's origin.
4 causes, each with a fixBack end
Browser blocks your Laravel API with a CORS error
Response to preflight request doesn't pass access control check
Laravel answers CORS preflights itself through its HandleCors middleware, driven by config/cors.php.
3 causes, each with a fixBack end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack end
composer require maatwebsite/excel fails to install
Composer says the package needs an older PHP than the one installed
Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.
3 causes, each with a fixBack end
composer install says the lock file is not compatible and asks for update
Your lock file does not contain a compatible set of packages. Please run composer update.
composer install checked the locked packages against this machine's PHP and extensions and found a conflict.
3 causes, each with a fixBack end
composer require laravel/horizon fails: ext-pcntl is missing
laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system
Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.
3 causes, each with a fix