Answer the question
In order to leave comments, you need to log in
How to set up CORS in Laravel?
Every time I need to send ajax requests to laravel, I run into the same problem. I get an error like
Access to XMLHttpRequest at 'xxx' from origin ' localhost:8080 ' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource ..
public function handle($request, Closure $next)
{
header('Access-Control-Allow-Headers: *');
header('Access-Control-Allow-Methods: *');
return $next($request);
}
Answer the question
In order to leave comments, you need to log in
Here is the package to use. https://github.com/barryvdh/laravel-cors
at the nginx level, you can configure the site for CORS. here is an example config https://gist.github.com/adiletmaks/cf2ff906ed0c9d3...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question