Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jornve's avatar

AngularJS - Laravel - Forge cors problem

Hello guys

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 my localhost to my api.domain.com i got a CORS error.

XMLHttpRequest cannot load http://api.domain.com/api/authenticate. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8888' is therefore not allowed access.

I googled for hours but i can't figure it out. I already tried adding CORS middleware to Laravel but that has no effect. { return $next($request) ->header('Access-Control-Allow-Origin', '*') ->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS') ->header('Access-Control-Max-Age', '1000') ->header('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With'); }

Error is still being showed. The weird part is that get request are allowed, only post requests are not allowed for some reason.

Can anyone help me out? Would be awesome! Greets from Belgium Jorn

0 likes
1 reply
jornve's avatar
jornve
OP
Best Answer
Level 1

I found a solution! For everyone that has the same problem, remove the CORS middleware and add the following lines to the Laravel index.php page (public/index.php)

header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS'); header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');

Worked for me, after hours of searching!

1 like

Please or to participate in this conversation.