title: Laravel handling CORS Options requests
body: <p>I am trying to make a small API that I could get an option request without a failure or error.
  I made this middleware:</p>
  <pre><code>public function handle($request, Closure $next)
  {
      if ($request-&gt;method() === 'OPTIONS') {
          $headers = [
              'Access-Control-Allow-Origin' =&gt; '*',
              'Access-Control-Allow-Methods'=&gt;'POST, GET, OPTIONS, PUT, DELETE'
          ];
          return (new Response(' ', 200))
              -&gt;withHeaders($headers);
      }
      else {
          return $next($request);
      };
  }
  </code></pre>
  <p>My <code>web.php</code>.</p>
  <pre><code>$router-&gt;get('/', function () use ($router) {
  return $router-&gt;app-&gt;version();
  });
  $router-&gt;get('/cors', 'CorsController@index');
  </code></pre>
  <p>When I send the request with postman it is okay, it adds headers to the response. However, but then any options request will get a 200 response and wont be redirected or anything.</p>
  <p>Earlier I tried doing this in my middleware:</p>
  <pre><code>public function handle($request, Closure $next)
  {
      return $next($request)
          -&gt;header('Access-Control-Allow-Origin', '*')
          -&gt;header('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS');
  }
  </code></pre>
  <p>But this always threw a <code>MethodNotAllowedError</code>.</p>
  <p>Also I use my request content when I create a new one.
  My question is how to handle options requests with CORS in laravel correctly, that it would not throw error and I would not lose my request content?</p>