How barryvdh/laravel-cors works
This is Laravel middleware for applying CORS policy to matching requests. A browser request enters the middleware, which checks configured paths; preflight requests receive a dedicated response, while other matching requests continue through Laravel and then receive CORS headers. The provider loads configuration and registers the CORS service. The tree does not include that service’s implementation, so its internal policy steps are not expanded; configuration options and Lumen support are documented in the README and source.
Main entry points: HandleCors.php Request middleware · CorsServiceProvider.php Service provider · cors.php CORS configuration
Components 7
Service setup
- Service provider
src/CorsServiceProvider.php
Request handling
- Request middleware
src/HandleCors.php - Laravel pipeline
- HTTP response
CORS policy
- CORS configuration
config/cors.php - PHP CORS service
Other components
- Browser client
Connections 10
- Browser client → Request middleware: sends request
- Service provider → CORS configuration: loads defaults
- Service provider → PHP CORS service: constructs with config
- Service provider → Request middleware: provides service
- Request middleware → CORS configuration: reads paths
- Request middleware → PHP CORS service: checks and adds headers
- Request middleware → Laravel pipeline: continues request
- Laravel pipeline → Request middleware: returns response
- Request middleware → HTTP response: returns response
- Browser client → HTTP response: receives response