Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Laravel
  3. Laravel CORS

Laravel CORS

MITPHPv3.0.0

A Laravel middleware package for handling Cross-Origin Resource Sharing (CORS) headers and pre-flight requests.

GitHubGitHub
6.2k stars608 forks0 contributors

What is Laravel CORS?

laravel-cors is a middleware package for Laravel that handles Cross-Origin Resource Sharing (CORS) headers and pre-flight OPTIONS requests. It solves the problem of enabling secure cross-origin API requests from web browsers by automatically adding the necessary CORS headers to responses and managing pre-flight checks.

Target Audience

Laravel and Lumen developers building RESTful APIs or web services that need to be consumed by frontend applications hosted on different domains or subdomains.

Value Proposition

Developers choose this package because it provides a robust, configurable, and framework-integrated solution for CORS handling, eliminating the need to manually manage CORS headers or write custom middleware. It follows Laravel conventions and offers detailed configuration options for complex cross-origin scenarios.

Overview

Adds CORS (Cross-Origin Resource Sharing) headers support in your Laravel application

Use Cases

Best For

  • Adding CORS support to Laravel REST APIs consumed by JavaScript SPAs
  • Configuring cross-origin requests between separate frontend and backend domains
  • Handling pre-flight OPTIONS requests for custom HTTP methods or headers
  • Securing APIs with specific allowed origins, headers, or credentials
  • Migrating CORS configuration from older Laravel versions to newer ones
  • Enabling CORS in Lumen microservice applications

Not Ideal For

  • Laravel 9.2+ projects where built-in CORS middleware is available and preferred
  • Teams prioritizing minimal third-party dependencies for long-term maintenance
  • Non-Laravel projects requiring CORS handling, as it's framework-specific
  • Developers needing active package updates and community support, since it's deprecated

Pros & Cons

Pros

Automatic Pre-flight Handling

Automatically responds to OPTIONS requests with correct CORS headers, eliminating manual pre-flight code, as stated in the README's features.

Granular Configuration Control

Offers extensive config options for paths, origins, headers, and methods via a dedicated config file, allowing precise security policies.

Lumen Framework Support

Provides full compatibility with Lumen through service provider registration, which lacks built-in CORS middleware.

Credential and Authorization Support

Configurable to include Access-Control-Allow-Credentials header, essential for APIs using authorization headers or cookies.

Cons

Deprecated for New Laravel

The package is deprecated since Laravel 9.2 includes CORS middleware in core, making it unnecessary and unsupported for current projects.

Configuration Complexity

Requires careful setup of paths and headers; misconfiguration leads to CORS errors, as highlighted in the 'Common problems' section.

Breaking Changes on Upgrade

Upgrading from older versions involved significant changes, such as new path properties and vendor name shifts, causing migration headaches.

Middleware Order Sensitivity

CORS headers can fail if middleware order is incorrect or if other middleware interrupts the flow, requiring debugging expertise.

Frequently Asked Questions

Quick Stats

Stars6,247
Forks608
Contributors0
Open Issues37
Last commit3 years ago
CreatedSince 2013

Tags

#hacktoberfest#lumen#laravel#cors#web-api#php#cross-origin#middleware#api-security

Built With

P
PHP
L
Laravel

Included in

Laravel13.0k
Auto-fetched 1 day ago

Related Projects

LiveWireLiveWire

A full-stack framework for Laravel that takes the pain out of building dynamic UIs.

Stars23,502
Forks1,735
Last commit1 day ago
Debug BarDebug Bar

Debugbar for Laravel (Integrates PHP Debug Bar)

Stars19,179
Forks1,607
Last commit1 day ago
IDE HelperIDE Helper

IDE Helper for Laravel

Stars14,891
Forks1,188
Last commit23 days ago
Intervention ImageIntervention Image

PHP Image Processing

Stars14,330
Forks1,491
Last commit5 days ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub