medz/cors
CORS middleware for Laravel that adds configurable Cross-Origin Resource Sharing headers, handles preflight OPTIONS requests, and supports allowed origins, methods, headers, credentials, and max-age settings. Easy to register and customize for APIs and web apps.
header() calls.OPTIONS handling, Vary: Origin for cache correctness, the illegal Access-Control-Allow-Origin: * + credentials combination, per-route overrides — are where teams ship bugs. The decision is rarely "write it ourselves"; it's "use what the framework already gives us" vs. "add a dependency."*.Consider it when:
Look elsewhere when:
HandleCors), descended from fruitcake/laravel-cors. Adding an archived third-party package to do what the framework already does is pure dependency risk with no upside.nelmio/cors-bundle is the maintained, idiomatic answer.Adoption gate: treat it as a stopgap with a named owner and a removal date, not as a permanent dependency. Add it to the dependency-review list and require a migration ticket at adoption time.
To executives: This is a small, MIT-licensed utility that solves a narrow, well-understood problem — letting our web and mobile clients talk to our APIs from other domains. It costs nothing, it's a one-line install, and it removes a recurring source of launch friction. The caveat is maintenance: the project was last released in 2020 and is archived, so it will not receive fixes. My recommendation is not to make it a platform standard. Where our frameworks already handle CORS natively — which is true for current Laravel — we should use that and carry no extra dependency. Where we're on a legacy stack that doesn't, this is a reasonable short-term bridge, provided we log it as technical debt with a removal plan. Net: low cost, low strategic value, non-trivial long-term risk if left unattended.
To engineering: It's a PSR-15 middleware with adapters for Laravel/Lumen, Slim, Swoft, and ThinkPHP. It gives you config-driven origin/method/header rules and per-route overrides, which is more ergonomic than scattering headers in controllers. Two caveats before you adopt: (1) it's archived since 2020 — assume no PHP 8.x or modern framework support until you've verified it yourself, and pin the version; (2) if you're on Laravel 7+, use the built-in HandleCors middleware instead and skip the dependency entirely. If we do adopt it on a legacy service, open a ticket to migrate to framework-native middleware at the next upgrade and make sure Vary: Origin and the wildcard-plus-credentials rule are covered by a test.
How can I help you explore Laravel packages today?