denismitr / laracors by denismitr

Cross Origin Resource Sharing Middleware for Laravel or Lumen
113
3
2
Package Data
Maintainer Username: denismitr
Maintainer Contact: denis.mitr@gmail.com (Denis Mitrofanov)
Package Create Date: 2017-06-10
Package Last Update: 2017-06-10
Language: PHP
License: MIT
Last Refreshed: 2024-12-14 15:14:03
Package Statistics
Total Downloads: 113
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 3
Total Watchers: 2
Total Forks: 1
Total Open Issues: 0

LARACORS

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.

Author

Denis Mitrofanov

TheCollection.ru

Installation


Use composer to install the package:

composer require denismitr/laracors

Laravel

Add to config/app.php:

'providers' => [
    ...
    \Denismitr\Laracors\LaravelCorsServiceProvider::class,
],

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 = [
    ...
    \Denismitr\Laracors\Cors::class
];

Publish the config file:

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

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

Named middleware
---------------
```php

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

protected $middlewareGroups = [
    'web' => [
        ...
    ],

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

Middleware parameters

Route::put('post/{id}', function ($id) {
    //
})->middleware('cors:get,post,put');

Lumen

Add the following lines to bootstrap/app.php:

$app->register('\Denismitr\Laracors\LumenCorsServiceProvider');
$app->middleware([
    .....
    '\Denismitr\Laracors\Cors',
]);