title: Laravel 4 API not allowing POST request from external site
body: <p>I am attempting to create a User via a POST request to my Laravel 4 API from an external site. I've added the following code to my app/filters.php file:</p>
  
  <pre><code>App::before(function($request)
  {
      if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
  
          header('Access-Control-Allow-Origin', 'http://www.myexternalsite.net');
          header('Allow', 'GET, POST, OPTIONS, PUT, DELETE');
          header('Access-Control-Allow-Headers', 'Origin, Content-Type, Accept, Authorization, X-Request-With');
          header('Access-Control-Allow-Credentials', 'true');
  
          exit;
      }
  });
  
  App::after(function($request, $response)
  {
      $response-&gt;headers-&gt;set('Access-Control-Allow-Origin', 'http://www.myexternalsite.net');
      $response-&gt;headers-&gt;set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
      $response-&gt;headers-&gt;set('Access-Control-Allow-Headers', 'Origin, Content-Type, Accept, Authorization, X-Requested-With');
      $response-&gt;headers-&gt;set('Access-Control-Allow-Credentials', 'true');
      $response-&gt;headers-&gt;set('Access-Control-Max-Age','86400');
      return $response;
  });
  </code></pre>
  
  <p>when I run my dev tools on the POST request from <a href="http://www.myexternalsite.net" rel="nofollow">http://www.myexternalsite.net</a> I get the following warning message:</p>
  
  <pre><code>event.returnValue is deprecated. Please use the standard event.preventDefault() instead. main-built.js:6
  </code></pre>
  
  <p>and the following error messages:</p>
  
  <pre><code>OPTIONS http://api.mywebsite.com/users 500 (Internal Server Error) main-built.js:7
  OPTIONS http://api.mywebsite.com/users No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.myexternalsite.net' is therefore not allowed access. main-built.js:7
  </code></pre>
  
  <p>Am I missing something?</p>