tenantcloud / laravel-cors
Send CORS headers in a Laravel application
Installs: 42 474
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 7
Forks: 1
Open Issues: 1
Requires
- php: >=8.2
- illuminate/contracts: ^10.0
- illuminate/support: ^9.0|^10.0
Requires (Dev)
- nunomaduro/larastan: ^2.6
- orchestra/testbench: ^8.5
- pestphp/pest: ^2.8
- php-cs-fixer/shim: ~3.19.2
- phpstan/phpstan: ~1.10.21
- phpstan/phpstan-mockery: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-webmozart-assert: ^1.2
- tenantcloud/php-cs-fixer-rule-sets: ~3.0.0
This package is auto-updated.
Last update: 2024-12-14 21:18:47 UTC
README
Laravel package for CORS, with support for custom CORS profiles per route.
Installation
In your composer.json
, add this repository:
"repositories": [
{
"type": "git",
"url": "https://github.com/tenantcloud/laravel-cors"
}
],
Then do composer require tenantcloud/laravel-cors
to install the package.
After, publish the config: php artisan vendor:publish
and select needed config file.
Usage
You want to use a single, global CORS per project
If you want to use a global profile, add CorsMiddleware::class
into your Http\Kernel.php
's
$middleware
. default
profile from the config will be used.
You want to use multiple different CORS profiles per route
If you need a scoped CORS, you should:
- Add wanted config to cors.php
- Add
'cors' => CorsMiddleware::class
into yourHttp\Kernel.php
's$routeMiddleware
. - Add
cors:your_profile
to route you want to have CORS on. - Add
OPTIONS
to list of supported methods for that route.
Example:
Route::match(['GET', 'OPTIONS'], '/test', 'Controller@test')->middleware('cors:test_profile');