title: Laravel API - AngularJS: Access-Control-Allow-Origin error
body: <p>Hello stackoverflowers!</p>
  
  <p>I have a hard time to get Angular and Laravel working together. I want to use Angular separately from Laravel. I have setup 2 domains app.domain.com and api.domain.com using forge. When i want to send requests from my app.domain.com or localhost to my api.domain.com i got a 'Access-Control-Allow-Origin' (=CORS?) error.</p>
  
  <p><strong>Error:</strong></p>
  
  <p>XMLHttpRequest cannot load <a href="http://api.domain.com/api/authenticate" rel="nofollow noreferrer">http://api.domain.com/api/authenticate</a>. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '<a href="http://localhost:8888" rel="nofollow noreferrer">http://localhost:8888</a>' is therefore not allowed access.</p>
  
  <p>I googled for hours but i can't figure it out. I already tried adding CORS middleware to Laravel but that has no effect. </p>
  
  <pre><code>{
          return $next($request)
              -&gt;header('Access-Control-Allow-Origin', '*')
              -&gt;header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
              -&gt;header('Access-Control-Max-Age', '1000')
              -&gt;header('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With');
  }
  </code></pre>
  
  <p>Error is still being showed. The weird part is that get request are allowed, only post requests are not allowed for some reason.</p>
  
  <p><a href="https://i.stack.imgur.com/dG7pV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dG7pV.png" alt="enter image description here"></a></p>
  
  <p>Normally i use APACHE as server but Laravel Forge is using nginx. Does this has something todo with nginx?  </p>
  
  <p><strong>My nginx config file:</strong></p>
  
  <pre><code>server {
  listen 80;
  server_name api.domain.be;
  root /home/forge/api.domain.be/public;
  
  # FORGE SSL (DO NOT REMOVE!)
  # ssl_certificate;
  # ssl_certificate_key;
  
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  
  index index.html index.htm index.php;
  
  charset utf-8;
  
  location / {
      try_files $uri $uri/ /index.php?$query_string;
  }
  
  location = /favicon.ico { access_log off; log_not_found off; }
  location = /robots.txt  { access_log off; log_not_found off; }
  
  access_log off;
  error_log  /var/log/nginx/api.onlinevaten.be-error.log error;
  
  error_page 404 /index.php;
  
  location ~ \.php$ {
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_pass unix:/var/run/php5-fpm.sock;
      fastcgi_index index.php;
      include fastcgi_params;
  }
  location ~ /\.ht {
      deny all;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Can anyone help me out? Would be awesome!</p>