denismitr / laracors
Cross Origin Resource Sharing Middleware for Laravel or Lumen
v0.6
2017-06-10 17:18 UTC
Requires
- php: ^5.6 || ^7.0 || ^7.1
- illuminate/http: 5.1.x|5.2.x|5.3.x|5.4.x
- illuminate/support: 5.1.x|5.2.x|5.3.x|5.4.x
- symfony/http-foundation: ~2.7|~3.0
- symfony/http-kernel: ~2.7|~3.0
Requires (Dev)
- mockery/mockery: ^0.9.9
- orchestra/testbench: ~3.0
- phpunit/phpunit: ^6.1
- satooshi/php-coveralls: ^1.0
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2024-11-23 08:43:36 UTC
README
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
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', ]);