Level 60
formData.append('_token', _token);
formData.append("_method", 'PUT');
fetch('/upload', {
method: 'POST',
body: formData,
})
This should do send a POST request with _method property set as 'PUT'
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I've been using the fetch API for a long time with POST like so:
let _token = document.querySelector('meta[name="csrf-token"]').content;
let form = document.getElementById("my-form");
let formData = new FormData(form);
formData.append("_token", _token);
fetch("/upload", {
method: "POST",
body: formData,
})
.then((response) => {
})
And in my web.php the route is:
Route::post('/upload', [MyController::class, 'upload']);
Now, I wanted to test it with PUT instead, so I changed the route method in web.php:
Route::put('/upload', [MyController::class, 'upload']);
And changed the fetch method:
fetch("/upload", {
method: "PUT",
body: formData,
})
.then((response) => {
})
But now I get 419 Page Expired as if I don't have a token. Why?
Thanks
formData.append('_token', _token);
formData.append("_method", 'PUT');
fetch('/upload', {
method: 'POST',
body: formData,
})
This should do send a POST request with _method property set as 'PUT'
Please or to participate in this conversation.