Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Api | 9,262 | 1,575 | 166 | 2 years ago | 72 | April 30, 2021 | 198 | bsd-3-clause | PHP | |
A RESTful API package for the Laravel and Lumen frameworks. | ||||||||||
Lumen | 7,592 | 77 | 66 | 9 months ago | 22 | November 24, 2020 | PHP | |||
The Laravel Lumen Framework. | ||||||||||
Laravel Swoole | 3,983 | 17 | 6 | a month ago | 55 | April 13, 2023 | 37 | mit | PHP | |
High performance HTTP server based on Swoole. Speed up your Laravel or Lumen applications. | ||||||||||
Laravel S | 3,780 | 9 | 8 | 10 hours ago | 227 | June 06, 2023 | 69 | mit | PHP | |
LaravelS is an out-of-the-box adapter between Laravel/Lumen and Swoole. | ||||||||||
Laravel Apidoc Generator | 3,385 | 124 | 26 | 3 months ago | 102 | May 28, 2020 | 55 | mit | PHP | |
Laravel API Documentation Generator | ||||||||||
Laravel Log Viewer | 3,048 | 663 | 64 | 2 months ago | 81 | February 15, 2023 | 41 | mit | PHP | |
:dromedary_camel: Laravel log viewer | ||||||||||
Seotools | 2,855 | 166 | 45 | 4 months ago | 47 | February 15, 2023 | 20 | mit | PHP | |
SEO Tools for Laravel | ||||||||||
Laravel Wechat | 2,809 | 345 | 57 | 7 months ago | 72 | October 17, 2022 | 1 | mit | PHP | |
微信 SDK for Laravel, 基于 overtrue/wechat | ||||||||||
Laravel Auditing | 2,745 | 122 | 59 | a month ago | 123 | June 19, 2023 | 11 | mit | PHP | |
Record the change log from models in Laravel | ||||||||||
Laravel Snappy | 2,450 | 454 | 53 | 2 months ago | 22 | February 05, 2023 | 34 | mit | PHP | |
Laravel Snappy PDF |
This package adds Cross-Origin Resource Sharing (CORS) support to your Laravel application.
The package is based on Framework agnostic (PSR-7) CORS implementation.
The current version V3 is designed for Laravel 6 or higher. If you use lower Laravel version please use V2.
composer require neomerx/cors-illuminate
For Lumen skip this step and see step 2.2
Create a config file by executing
php artisan vendor:publish --provider="Neomerx\CorsIlluminate\Providers\LaravelServiceProvider"
it will create config/cors-illuminate.php
file in you application.
Add CORS middleware to your HTTP stack at app/Http/Kernel.php
file. The middleware should be added to $middleware
list which is executed for all routes (even non declared in your routes file). Preferably before 'heavy' middleware for performance reasons.
class Kernel extends HttpKernel
{
...
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\Neomerx\CorsIlluminate\CorsMiddleware::class, // <== add this line
...
];
...
}
Next see step 3
For Laravel skip this step
In bootstrap/app.php
add CORS to global middleware list
$app->middleware([
...
\Neomerx\CorsIlluminate\CorsMiddleware::class,
]);
and register CORS provider
$app->register(\Neomerx\CorsIlluminate\Providers\LumenServiceProvider::class);
As Lumen does not support vendor:publish
command file vendor/neomerx/cors-illuminate/config/cors-illuminate.php
have to be manually copied to config/cors-illuminate.php
.
Next see step 3
Configuration file is extensively commented so it will be easy for you to set up it for your needs. First settings you need to configure are server origin (URL) and allowed origins
...
/**
* Could be string or array. If specified as array (recommended for
* better performance) it should be in parse_url() result format.
*/
Settings::KEY_SERVER_ORIGIN => [
'scheme' => 'http',
'host' => 'localhost',
'port' => 1337,
],
/**
* A list of allowed request origins (no trail slashes).
* If value is not on the list it is considered as not allowed.
* If you want to allow all origins remove/comment this section.
*/
Settings::KEY_ALLOWED_ORIGINS => [
'http://localhost:4200',
],
...
When exceptions are thrown and responses are created in Laravel/Lumen exception handlers middleware will be excluded from handling responses. It means CORS middleware will not add its CORS headers to responses. For this reason CORS results (including headers) are registered in Laravel/Lumen Container and made accessible from any part of your application including exception handlers.
Code sample for reading CORS headers
use Neomerx\Cors\Contracts\AnalysisResultInterface;
$corsHeaders = [];
if (app()->resolved(AnalysisResultInterface::class) === true) {
/** @var AnalysisResultInterface $result */
$result = app(AnalysisResultInterface::class);
$corsHeaders = $result->getResponseHeaders();
}
This package provides a number of ways how its behaviour could be customized.
The following methods of class CorsMiddleware
could be replaced in descendant classes
getResponseOnError
You can override this method in order to customize error reply.getCorsAnalysis
You can override this method to modify how CORS analysis result is saved to Illuminate Container.getRequestAdapter
You can override this method to replace IlluminateRequestToPsr7
adapter with another one.Additionally a custom AnalysisStrategyInterface could be injected by
getCreateAnalysisStrategyClosure
method in ServiceProvider
for Laravel/LumenAnalysisStrategyInterface
Also custom AnalyzerInterface could be injected by
getCreateAnalyzerClosure
method in ServiceProvider
for Laravel/LumenAnalyzerInterface
composer test
Pull requests for documentation and code improvements (PSR-2, tests) are welcome.
This package is using Semantic Versioning.
Apache License (Version 2.0). Please see License File for more information.