CORS
CORS headers allow browsers to make cross-origin requests to your API. In Laravel, configure the built-in CORS middleware.
CORS headers allow browsers to make cross-origin requests to your API. In Laravel, configure the built-in CORS middleware.
// config/cors.php (Laravel)
return [
"paths" => ["api/*"],
"allowed_methods" => ["*"],
"allowed_origins" => ["https://app.example.com"],
"allowed_headers" => ["*"],
"exposed_headers" => ["X-RateLimit-Remaining"],
"max_age" => 600,
"supports_credentials" => true,
];
// Plain PHP manual headers
header("Access-Control-Allow-Origin: https://app.example.com");
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
Never set Access-Control-Allow-Origin: * on authenticated APIs — it defeats CORS protection.