Sending file with some other inputs via JS Fetch API
I am trying to send a file with some other inputs to a LARAVEL project. the problem is that when I use body: JSON.stringify(data) , the File is an empty array when I dd(request()->all().
I have tried to remove the "Content-Type": "application/json", but then the whole request()->all() and $_POST is empty.
by the way I am not using data = new FormData() and I am creating my data manually (I mean I loop through every element in the form and create an array. this is done because I want to send inputs with the array name to be the actual array when sending to a php endpoint exactly like what HTML does <input name="facilities[]" id="input-1"> <input name="facilities[]" id="input-2">).
Thanks a lot @tray2 .
How can I append inputs with array name as an array so php will get the array as it gets from HTML form submit. The file and other inputs are OK and they are working fine, But when there are inputs which have name as an array "<input name="facilities[]" id="input-1"> <input name="facilities[]" id="input-2">", It messes every thing
Allright, so this is what I am going to do: 1. create FormData() object and pass the file input and then 2. loop through my inputs and create an array and append that array to the FormData().
Am I right ?