For the time being I've used POST and added _method to the FormData
form.append('_method', 'PATCH');
If anyone has a better solution to this then that would be appreciated. Thanks!
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm using Axios HTTP requests however, I've also tried using jQuery ajax and getting the same result
let files = e.target.files || e.dataTransfer.files;
if (!files.length) {
return;
}
let form = new FormData();
form.append('profile_picture', files[0]);
axios.patch('/profile', form)
.then((response) => {
console.log(response);
});
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
url: '/profile',
type: 'patch',
data: form,
cache: false,
dataType: 'json',
processData: false,
contentType: false,
success: function(response) {
console.log(response);
}
});
When it's a PATCH request the file does not appear in the request in Laravel. However, when I change it to POST the file appears correctly. Has anyone come across this and have a way to get this working using PATCH request? Or is it fine to use POST even though I'm updating a record?
Thanks!
For the time being I've used POST and added _method to the FormData
form.append('_method', 'PATCH');
If anyone has a better solution to this then that would be appreciated. Thanks!
Please or to participate in this conversation.