I have a form I am trying to submit with an image file.
The problem is that no image file is being sent.
My AJAX call:
$(document).on('submit', ".hidden-image-upload", function(e){
e.preventDefault();
$.ajax({
url:'/project/uploadImage',
data: new FormData($(".hidden-image-upload")[0]),
headers: {
'X-CSRF-Token': $('form.hidden-image-upload [name="_token"]').val()
},
dataType:'json',
async:false,
type:'post',
processData: false,
contentType: false,
success:function(response){
console.log(response);
},
});
});
And then my form:
{!! Form::open(['class' => 'hidden-image-upload', 'files' => true]) !!}
{!! Form::file('file', ['class' => 'cover-image-upload-button']) !!}
{!! Form::close() !!}
In my controller I am just returning:
return $request->all();
And I am getting:
_token: "lFHIf7wiYI3IWqrbcpKxgJEPtXCIVpLm5nVhJ1Ks", file: {}}
_token: "lFHIf7wiYI3IWqrbcpKxgJEPtXCIVpLm5nVhJ1Ks"
file: {}
Any help?