Cross Origin Resource Sharing Middleware for Laravel or Lumen

v0.6 2017-06-10 17:18 UTC

This package is auto-updated.

Last update: 2022-09-23 03:58:05 UTC


Laravel Cross Origin Resource Sharing Middleware

This middleware is designed specifically for the Laravel and Lumen frameworks and the RESTful APIs builded with them. It allows requests to made from JS frontends of other apps.


Denis Mitrofanov


Use composer to install the package:

composer require denismitr/laracors


Add to config/app.php:

'providers' => [

Include in your app/Http/Kernel.php to the appropriate section (all requests if all your routes are API or named middleware + API middleware group to make it work for every api route or just named middleware):

Global middleware

protected $middleware = [

Publish the config file:

php artisan vendor:publish  --provider="Denismitr\Laracors\LaravelCorsServiceProvider"

Edit the config/laracors.php file to your needs.

Named middleware

protected $routeMiddleware = [
    'cors' => \Denismitr\Laracors\LaravelCorsServiceProvider::class,

protected $middlewareGroups = [
    'web' => [

    'api' => [

Middleware parameters

Route::put('post/{id}', function ($id) {


Add the following lines to bootstrap/app.php: