Register the CatchAllOptionsRequestsProvider
service provider in bootstrap/app.php
which will check the incoming request and response successfully if it is an OPTIONS
request.
Add the CorsMiddleware
to the $app->middleware([
array in bootstrap/app.php
which will attach the following CORS headers to all responses:
- allow all headers
- allow requests from all origins
- allow all the headers which were provided in the request
thanks @davidnknight @rgehan
You're right, all of this Middleware logic can be placed just in the middleware file and not also in a ServiceProvider.
ref:
https://gist.github.com/danharper/06d2386f0b826b669552#gistcomment-1694593
https://gist.github.com/danharper/06d2386f0b826b669552#gistcomment-2013919