Yes, Inertia automatically adds the CSFR token in every POST request. The documentation shows how to do it because it's framework agnostic, but with Laravel it's done underneath by Axios.
Jun 23, 2022
5
Level 2
InertiaJS include CSRF Token
With jQuery you must include a CSRF token otherwise the request will FAIL. See code snippet.
$.ajax({
type : "POST",
url : "/landlords",
data : {
_token:$('meta[name="csrf-token"]').attr('content'),
'll_code':$('input[name=ll_code]').val(),
'first_name':$('input[name=first_name]').val(),
'middle_name':$('input[name=middle_name]').val(),
'last_name':$('input[name=last_name]').val(),
}
But If I submit a request with Inertia without CSRF token it WORKS. See code snippet below.
<script>
let values = {
first_name: null,
last_name: null,
class_name: null,
}
function handleSubmit() {
Inertia.post('/students', values)
}
</script>
Does this mean inertia includes the CSRF token automatically?
Disclaimer: Inertiajs Documentation show how to include a CSRF token.
Level 2
1 like
Please or to participate in this conversation.