PHPackages                             adoranwodo/laravelcorsmiddleware - 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. adoranwodo/laravelcorsmiddleware

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

adoranwodo/laravelcorsmiddleware
================================

Add CORS support to your Lumen / Laravel application

1.0.1(7y ago)3264osl-3.0PHP

Since Nov 1Pushed 6y ago1 watchersCompare

[ Source](https://github.com/AdoraNwodo/laravel-cors-middleware)[ Packagist](https://packagist.org/packages/adoranwodo/laravelcorsmiddleware)[ Docs](https://github.com/adoranwodo/laravelcorsmiddleware)[ RSS](/packages/adoranwodo-laravelcorsmiddleware/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (5)Versions (4)Used By (0)

LaravelCorsMiddleware
=====================

[](#laravelcorsmiddleware)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3771f4d0f328ea905936ad02441c7f44c70e91ae5a1b049f37491dcae3f4495d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61646f72616e776f646f2f6c61726176656c636f72736d6964646c65776172652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/adoranwodo/laravelcorsmiddleware)[![Total Downloads](https://camo.githubusercontent.com/2c60bde25adc89d1c51aafeff3bc006806dc985299db6be86b01a5b84fc5a188/68747470733a2f2f706f7365722e707567782e6f72672f61646f72616e776f646f2f6c61726176656c636f72736d6964646c65776172652f646f776e6c6f616473)](https://packagist.org/packages/adoranwodo/laravelcorsmiddleware)[![Build Status](https://camo.githubusercontent.com/6edea0058cbc935ada1192fb868f66f1735f33bb6b49132cd44cd8876a2a4137/68747470733a2f2f73656d6170686f726563692e636f6d2f6170692f76312f61646f72616e776f646f2f6c61726176656c2d636f72732d6d6964646c65776172652f6272616e636865732f6d61737465722f736869656c64735f62616467652e737667)](https://semaphoreci.com/adoranwodo/laravel-cors-middleware)[![License](https://camo.githubusercontent.com/59f571a6c3c5677b90e7574491d01c7f6ebaaae4fc54ab689e1d2573c732dc33/68747470733a2f2f706f7365722e707567782e6f72672f61646f72616e776f646f2f6c61726176656c636f72736d6964646c65776172652f6c6963656e7365)](https://packagist.org/packages/adoranwodo/laravelcorsmiddleware/)[![composer.lock available](https://camo.githubusercontent.com/ccee1162655d87fd3c2eef1fce520394a4d3aae3dc97c03c14bd1ab17b64026c/68747470733a2f2f706f7365722e707567782e6f72672f61646f72616e776f646f2f6c61726176656c636f72736d6964646c65776172652f636f6d706f7365726c6f636b)](https://packagist.org/packages/adoranwodo/laravelcorsmiddleware)

Laravel Cors Middleware is a package that allows users enable Cross-Origin Resource Sharing (CORS) for their Laravel / Lumen applications by taking advantage of the middleware configuration.

Installation
============

[](#installation)

Via Composer

```
$ composer require adoranwodo/laravelcorsmiddleware
```

Usage
=====

[](#usage)

Laravel
-------

[](#laravel)

If you are using Laravel, please continue here. If you are using Lumen, please scroll down to the Lumen section.

### Configuration

[](#configuration)

Please add the service provider to your `config/app.php` :

```
'providers' => [
  ...
  AdoraNwodo\LaravelCorsMiddleware\LaravelCorsMiddlewareServiceProvider::class
]

```

There is a default configuration in `config/laravelcorsmiddleware.php`. Publish this file to your own config directory and change to your own values. You can publish the file by running the code below in your terminal:

```
php artisan vendor:publish --provider="AdoraNwodo\LaravelCorsMiddleware\LaravelCorsMiddlewareServiceProvider"

```

There are some instructions in the config. Please adhere strictly and you should be fine :).

Finally, you need to add this to your middleware. You can add it globally or to a middleware group.

### Global Middleware (Laravel)

[](#global-middleware-laravel)

To use the CORS middleware globally (on all routes), go to `app/Http/Kernel.php` and add the laravelcorsmiddleware to your `$middleware` array like this:

```
protected $middleware = [
  ...
  \AdoraNwodo\LaravelCorsMiddleware\LaravelCorsMiddleware::class,
]

```

### Middleware Group (Laravel)

[](#middleware-group-laravel)

To use the CORS middleware only for specific routes or groups, go to `app/Http/Kernel.php` and add the laravelcorsmiddleware to your middleware group array like this:

```
protected $middlewareGroups = [
    'web' => [
        ...
        \AdoraNwodo\LaravelCorsMiddleware\LaravelCorsMiddleware::class,
    ],

    'api' => [
        ...
    ],
];

```

Lumen
-----

[](#lumen)

If you are using Lumen, please continue here. If you are using Laravel, please scroll up to the Laravel section

### Configuration

[](#configuration-1)

Please create a `/config` directory in the parent directory and add create a new `laravelcorsmiddleware.php` file. Paste this into your new php file (You can edit the values as you like).

```
