Antlers with Htmx 419 Error

Published on March 6th, 2024 by Timo

When doing a Post request to a route laravel expects a csrf token.

Csrf tokens can be added to antlers without adding a form by using htmx.

Laravel expects X-CSRF-TOKEN as a Header-key for the csrf token.

You only need to change "Csrftoken" with your backend created csrf token.

<div hx-post="/example" hx-headers='{"X-CSRF-TOKEN": "My Value"}'> ... </div>