PHPackages                             neomerx/cors-illuminate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. neomerx/cors-illuminate

ActiveLibrary[HTTP &amp; Networking](/categories/http)

neomerx/cors-illuminate
=======================

CORS (Cross-Origin Resource Sharing) support for Laravel and Lumen

v3.0.0(6y ago)4896.9k↑68.3%6[1 issues](https://github.com/neomerx/cors-illuminate/issues)[1 PRs](https://github.com/neomerx/cors-illuminate/pulls)2Apache-2.0PHPPHP &gt;=7.2.0CI failing

Since Aug 7Pushed 5y ago4 watchersCompare

[ Source](https://github.com/neomerx/cors-illuminate)[ Packagist](https://packagist.org/packages/neomerx/cors-illuminate)[ Docs](https://github.com/neomerx/cors-illuminate)[ RSS](/packages/neomerx-cors-illuminate/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (9)Versions (14)Used By (2)

[![Project Management](https://camo.githubusercontent.com/63ac17ae1fbd0235e8a27913843ab6ad454a14a972edf419bff7799e52d2fe11/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70726f6a6563742d6d616e6167656d656e742d626c75652e737667)](https://waffle.io/neomerx/cors-illuminate)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/9ed9b70cd1c6ae1e7e6dc49f842efebbaa15aad7ad0aab88ce4ad56708396bc2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e656f6d6572782f636f72732d696c6c756d696e6174652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/neomerx/cors-illuminate/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/5a3a52e962d6b103a6ef1df4068e20c37429d797a32e75195ad11f0584ced75e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e656f6d6572782f636f72732d696c6c756d696e6174652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/neomerx/cors-illuminate/?branch=master)[![Build Status](https://camo.githubusercontent.com/d9992aa3b1639d49f21a1c1bc8a02c5f0fca5856bcc9ff4311208fd34bcc0627/68747470733a2f2f7472617669732d63692e6f72672f6e656f6d6572782f636f72732d696c6c756d696e6174652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/neomerx/cors-illuminate)[![License](https://camo.githubusercontent.com/49901da8ac7a5f04784429fcdbcbc13f248b7b5376ab66d8d22fa5403093f884/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6e656f6d6572782f636f72732d696c6c756d696e6174652e737667)](https://packagist.org/packages/neomerx/cors-illuminate)

Description
-----------

[](#description)

This package adds [Cross-Origin Resource Sharing](http://www.w3.org/TR/cors/) (CORS) support to your Laravel application.

The package is based on [Framework agnostic (PSR-7) CORS implementation](https://github.com/neomerx/cors-psr7).

The **current version V3** is designed for Laravel 6 or higher. If you use lower Laravel version please use **V2**.

Install
-------

[](#install)

### 1 Composer

[](#1-composer)

```
composer require neomerx/cors-illuminate

```

### 2.1 Laravel

[](#21-laravel)

> For Lumen skip this step and see step 2.2

Create a config file by executing

```
php artisan vendor:publish --provider="Neomerx\CorsIlluminate\Providers\LaravelServiceProvider"

```

it will create `config/cors-illuminate.php` file in you application.

Add CORS middleware to your HTTP stack at `app/Http/Kernel.php` file. The middleware should be added to `$middleware` list which is executed for all routes (even non declared in your routes file). Preferably before 'heavy' middleware for performance reasons.

```
class Kernel extends HttpKernel
{
    ...

    protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        \Neomerx\CorsIlluminate\CorsMiddleware::class, //  Next see step 3

### 2.2 Lumen

[](#22-lumen)

> For Laravel skip this step

In `bootstrap/app.php` add CORS to global middleware list

```
$app->middleware([
    ...
    \Neomerx\CorsIlluminate\CorsMiddleware::class,
]);
```

and register CORS provider

```
$app->register(\Neomerx\CorsIlluminate\Providers\LumenServiceProvider::class);
```

As Lumen does not support `vendor:publish` command file `vendor/neomerx/cors-illuminate/config/cors-illuminate.php` have to be manually copied to `config/cors-illuminate.php`.

> Next see step 3

### 3 Configuration

[](#3-configuration)

[Configuration file](config/cors-illuminate.php) is extensively commented so it will be easy for you to set up it for your needs. First settings you need to configure are server origin (URL) and allowed origins

```
    ...

    /**
     * Could be string or array. If specified as array (recommended for
     * better performance) it should be in parse_url() result format.
     */
    Settings::KEY_SERVER_ORIGIN => [
        'scheme' => 'http',
        'host'   => 'localhost',
        'port'   => 1337,
    ],

    /**
     * A list of allowed request origins (no trail slashes).
     * If value is not on the list it is considered as not allowed.
     * If you want to allow all origins remove/comment this section.
     */
    Settings::KEY_ALLOWED_ORIGINS => [
        'http://localhost:4200',
    ],

    ...
```

Exceptions and CORS headers
---------------------------

[](#exceptions-and-cors-headers)

When exceptions are thrown and responses are created in [Laravel/Lumen exception handlers](https://laravel.com/docs/6.x/errors) middleware will be excluded from handling responses. It means CORS middleware will not add its CORS headers to responses. For this reason CORS results (including headers) are registered in [Laravel/Lumen Container](https://laravel.com/docs/6.x/container) and made accessible from any part of your application including exception handlers.

Code sample for reading CORS headers

```
use Neomerx\Cors\Contracts\AnalysisResultInterface;

$corsHeaders = [];
if (app()->resolved(AnalysisResultInterface::class) === true) {
    /** @var AnalysisResultInterface $result */
    $result = app(AnalysisResultInterface::class);
    $corsHeaders = $result->getResponseHeaders();
}
```

Customization
-------------

[](#customization)

This package provides a number of ways how its behaviour could be customized.

The following methods of class `CorsMiddleware` could be replaced in descendant classes

- `getResponseOnError` You can override this method in order to customize error reply.
- `getCorsAnalysis` You can override this method to modify how CORS analysis result is saved to Illuminate Container.
- `getRequestAdapter` You can override this method to replace `IlluminateRequestToPsr7` adapter with another one.

Additionally a custom [AnalysisStrategyInterface](https://github.com/neomerx/cors-psr7/blob/master/src/Contracts/AnalysisStrategyInterface.php) could be injected by

- overriding `getCreateAnalysisStrategyClosure` method in `ServiceProvider` for Laravel/Lumen
- using [Laravel/Lumen Container binding](https://laravel.com/docs/6.x/container) for interface `AnalysisStrategyInterface`

Also custom [AnalyzerInterface](https://github.com/neomerx/cors-psr7/blob/master/src/Contracts/AnalyzerInterface.php) could be injected by

- overriding `getCreateAnalyzerClosure` method in `ServiceProvider` for Laravel/Lumen
- using [Laravel/Lumen Container binding](https://laravel.com/docs/6.x/container) for interface `AnalyzerInterface`

Testing
-------

[](#testing)

```
composer test

```

Contributing
------------

[](#contributing)

Pull requests for documentation and code improvements (PSR-2, tests) are welcome.

Versioning
----------

[](#versioning)

This package is using [Semantic Versioning](http://semver.org/).

License
-------

[](#license)

Apache License (Version 2.0). Please see [License File](LICENSE) for more information.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~148 days

Recently: every ~344 days

Total

12

Last Release

2346d ago

Major Versions

v0.2.0 → v1.0.02015-12-22

v1.1.2 → v2.0.02016-04-25

v2.0.2 → v3.0.02020-01-30

PHP version history (3 changes)v0.1.0PHP &gt;=5.5.0

v2.0.2PHP &gt;=5.6.0

v3.0.0PHP &gt;=7.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/0da01dc445667261310b897ad80724e8c63130515b03159c79b1eeb2f3983c9a?d=identicon)[neomerx](/maintainers/neomerx)

---

Top Contributors

[![neomerx](https://avatars.githubusercontent.com/u/10420662?v=4)](https://github.com/neomerx "neomerx (27 commits)")

---

Tags

laravelcorslumenneomerxCross-Origin Resource Sharing

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/neomerx-cors-illuminate/health.svg)

```
[![Health](https://phpackages.com/badges/neomerx-cors-illuminate/health.svg)](https://phpackages.com/packages/neomerx-cors-illuminate)
```

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[laravel/nightwatch

The official Laravel Nightwatch package.

36210.1M36](/packages/laravel-nightwatch)[mimmi20/browser-detector

Library to detect Browsers and Devices

48157.5k5](/packages/mimmi20-browser-detector)[neomerx/cors-psr7

Framework agnostic (PSR-7) CORS implementation (www.w3.org/TR/cors/)

682.5M22](/packages/neomerx-cors-psr7)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
