Is the route in your api.php routes file or web.php?
I ask because routes in api.php don't have sessions and therefore don't have csrf token checking
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am currently building a Laravel app that uses Angular for some parts of the frontend. Now I noticed that Laravel's CSRF protection is not working correctly when I am submitting forms via Angular.
My Angular form submit looks basically like this:
$http.post(appUrl + '/name', {
name: name
}).then(function (response) {
console.log(response.data);
});
In my web.php routes file I route the post request to /name to a controller method that looks like this:
public function postName() {
return response()->json([
'lorem' => 'ipsum'
]);
}
Now if I run the post submit, the method's response is being logged in my browser's console. I am wondering why this is, since nowhere I am sending a CSRF token. If I try to submit the form to the same route without Angular the expected TokenMismatchException will be thrown.
Nowhere in my code I am sending a CSRF token with the Angular POST request, so it basically should throw a TokenMismatchException. What is the problem here?
You can see if the csrf token is being sent by looking at the network request in your browser developer tools
Please or to participate in this conversation.