fruitcake/laravel-cors
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
fruitcake/php-cors | v1.3.0 | 6.44 kB | MIT | prod | |
illuminate/contracts | v9.52.16 | 67.37 kB | MIT | prod | |
illuminate/support | v9.52.16 | 102.2 kB | MIT | prod |
The fruitcake/laravel-cors
is a robust middleware for Laravel applications that handles Cross-Origin Resource Sharing (CORS) requests. This package provides a way to add CORS headers to the responses generated by your Laravel application. It effectively handles CORS pre-flight OPTIONS requests and customizes the routes on which CORS will be applied.
To use the fruitcake/laravel-cors
package, you must first require it in your composer.json
file and then update the dependencies:
composer require fruitcake/laravel-cors
In case there exists any conflict with older versions of barryvdh/laravel-cors
or fruitcake/laravel-cors
, remove the conflicting package and then try installing again:
composer remove barryvdh/laravel-cors fruitcake/laravel-cors
composer require fruitcake/laravel-cors
After the successful installation, you must add the HandleCors
middleware at the top of the $middleware property of app/Http/Kernel.php
class:
protected $middleware = [
\Fruitcake\Cors\HandleCors::class,
// ...
];
Update the configuration to define the paths on which CORS services should run:
'paths' => ['api/*'],
Further customize CORS behavior by publishing the configuration into your own config:
php artisan vendor:publish --tag="cors"
And using settings like 'allowed_headers', 'allowed_methods', etc. in config/cors.php
.
The entire documentation for the fruitcake/laravel-cors
package can be found directly by visiting the GitHub repository of the package - fruitcake/laravel-cors GitHub repo. It contains information about package features, installation, usage, configuration, as well as potential issues and solutions.