Example middleware for laravel CORS headers if request method OPTIONS. Working in Laravel >= 5.4, maybe 5.3.
For use OptionsCorsResponse middleware, copy it for your application and enable it in Kernel::$middleware
array (but not in Kernel::$routeMiddleware, see laravel/framework#19938).
// App\Http\Kernel
// ...
protected $middleware = [
// ...
\App\Http\Middleware\OptionsCorsResponse::class,
];
Сhange $headers
in OptionsCorsResponse
if necessary.