New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

neomerx/cors-illuminate

CORS (Cross-Origin Resource Sharing) support for Laravel and Lumen
97,231 48

Larablocks Analysis

neomerx/cors-illuminate works with Laravel 6 (latest release v3.0.0, Jan 30, 2020), which reached end of life on Sep 6, 2022: no more fixes, even for security.

Laravel 5 in earlier releases.

Recommendation checks

Not advised

Not advised: no release or commit in over 2 years.

  • No release or commit in over 2 years
  • Supports only Laravel 6, past end of life since Sep 6, 2022
  • No release in the last 12 months (last: Jan 30, 2020)
  • 63 downloads a month (needs 10,000)
  • 48 GitHub stars (needs 100)

State

Likely abandoned
  • No release or commit in over 2 years.
  • Last stable release: Jan 30, 2020.
  • No releases in the last 12 months.
  • First released: Aug 7, 2015.
  • Monthly downloads: 63, down 33% from six months ago.
  • 2 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Dec 3, 2026.

Install
composer require neomerx/cors-illuminate
Latest Version:v3.0.0
PHP:>=7.2.0
Laravel:6
Older releases:5
License:Apache-2.0
Last Updated:Dec 30, 2020
Links: GitHub  ·  Packagist
Maintainer: neomerx

Project Management Scrutinizer Code Quality Code Coverage Build Status License

Description

This package adds Cross-Origin Resource Sharing (CORS) support to your Laravel application.

The package is based on Framework agnostic (PSR-7) CORS implementation.

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

Install

1 Composer

composer require neomerx/cors-illuminate

2.1 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, // <== add this line
        
        ...
    ];
    
    ...
}

Next see step 3

2.2 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

Configuration file 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

When exceptions are thrown and responses are created in Laravel/Lumen exception handlers 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 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

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 could be injected by

  • overriding getCreateAnalysisStrategyClosure method in ServiceProvider for Laravel/Lumen
  • using Laravel/Lumen Container binding for interface AnalysisStrategyInterface

Also custom AnalyzerInterface could be injected by

Testing

composer test

Contributing

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

Versioning

This package is using Semantic Versioning.

License

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

Related Packages

yocome/lumen-cors

cors for Lumen

1,788 1
kamiorz/lumen-cors

cors for Lumen

1,707 0
maxim-sarandev/lumen-swagger-cors

CORS configuration added to the base Swagger Lumen repo

1,139 0
mahmoud-birdsol/cors-laravel

Laravel Cross origin resource sharing package

566 1
denismitr/laracors

Cross Origin Resource Sharing Middleware for Laravel or Lumen

113 3

Version History

Version Released PHP Laravel License
v3.0.0 >=7.2.0 ^6.0 Apache-2.0
v2.0.2 >=5.6.0 ^5.1 Apache-2.0
v2.0.1 >=5.5.0 ^5.1 Apache-2.0
v2.0.0 >=5.5.0 ^5.1 Apache-2.0
v1.1.2 >=5.5.0 ^5.1 Apache-2.0