CORS middlware running on preflight OPTIONS request but not on main request
<p>I've created a middleware that handles my CORS requests:</p>

<pre><code>    &lt;?php

namespace App\Http\Middleware;

use Closure;

class Cors
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
      $headers = [
           'Access-Control-Allow-Methods' =&gt; 'POST, GET, OPTIONS, PUT, DELETE',
           'Access-Control-Allow-Headers' =&gt; 'Content-Type, X-Auth-Token, Origin, Authorization',
           'Access-Control-Allow-Origin' =&gt; '*'
       ];

     $response = $next($request);
     foreach ($headers as $key =&gt; $value){
       $response-&gt;headers-&gt;set($key, $value);
      }
     return $response;
    }
}
</code></pre>

<p>And I've added it to my <code>kernel.php</code>: </p>

<pre><code>'api' =&gt; [
        'throttle:60,1',
        'bindings',
        'cors'
    ],
</code></pre>

<p>When I make a <code>GET</code> request to <code>/user</code> everything works fine, but when I make a <code>POST</code> request to <code>/api/answers</code> I get a CORS error: <code>XMLHttpRequest cannot load http://localhost:8000/api/answers. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.</code>. Both are in my <code>api.php</code>:</p>

<pre><code>    &lt;?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::group(['middleware' =&gt; ['auth:api']], function () {
    Route::get('/user', function (Request $request) {
        $user = $request-&gt;user();
        $user-&gt;load('locations.company');
        $user-&gt;load([
            'questionlists' =&gt; function ($query) {
                $query-&gt;with('questions.type');
                $query-&gt;with('difficulty');
            }
        ]);

        $amountOfCompletes = count($user-&gt;completes);
        $user-&gt;amountOfCompletes = $amountOfCompletes;
        return $user;
    });

    Route::resource('answers', 'AnswersController');
});
</code></pre>