Download the PHP package elevationdigital/laravel-cors without Composer
On this page you can find all versions of the php package elevationdigital/laravel-cors. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download elevationdigital/laravel-cors
More information about elevationdigital/laravel-cors
Files in elevationdigital/laravel-cors
Package laravel-cors
Short Description Adds CORS (Cross-Origin Resource Sharing) headers support in your Laravel application
License MIT
Informations about the package laravel-cors
CORS Middleware for Laravel
Based on https://github.com/asm89/stack-cors
About
The laravel-cors
package allows you to send Cross-Origin Resource Sharing
headers with Laravel middleware configuration.
If you want to have a global overview of CORS workflow, you can browse this image.
Upgrading from 0.x
When upgrading from 0.x versions, there are some breaking changes:
- The vendor name has changed (see installation/usage)
- Group middleware is no longer supported.
- A new 'paths' property is used to enable/disable CORS on certain routes. This is empty by default!
Features
- Handles CORS pre-flight OPTIONS requests
- Adds CORS headers to your responses
- Match routes to only add CORS to certain Requests
Installation
Require the fruitcake/laravel-cors
package in your composer.json
and update your dependencies:
Global usage
To allow CORS for all your routes, add the HandleCors
middleware in the $middleware
property of app/Http/Kernel.php
class:
Now update the config to define the paths you want to run the CORS service on, (see Configuration below):
Configuration
The defaults are set in config/cors.php
. Publish the config to copy the file to your own config:
Note: When using custom headers, like
X-Auth-Token
orX-Requested-With
, you must set theallowed_headers
to include those headers. You can also set it to['*']
to allow all custom headers.Note: If you are explicitly whitelisting headers, you must include
Origin
or requests will fail to be recognized as CORS.
allowed_origins
, allowed_headers
and allowed_methods
can be set to ['*']
to accept any value.
Note: Try to be a specific as possible. You can start developing with loose constraints, but it's better to be as strict as possible!
Note: Because of http method overriding in Laravel, allowing POST methods will also enable the API users to perform PUT and DELETE requests as well.
Lumen
On Laravel Lumen, just register the ServiceProvider manually:
Global usage for Lumen
To allow CORS for all your routes, add the HandleCors
middleware to the global middleware and set the paths
property in the config.
Disabling CSRF protection for your API
If possible, use a different route group with CSRF protection enabled.
Otherwise you can disable CSRF for certain requests in App\Http\Middleware\VerifyCsrfToken
:
License
Released under the MIT License, see LICENSE.
All versions of laravel-cors with dependencies
illuminate/support Version ^5.5|^6.0|^7.0
symfony/http-foundation Version ^3.3|^4|^5.0
symfony/http-kernel Version ^3.3|^4|^5.0
asm89/stack-cors Version ^1.3