I have this form and I need to be able to post data to the server through ajax, a user can upload 1 or more photos, or they may not upload any photos at all, anyway how can I send the data taken from the `type=file input and upload it to the server in the background?
Here's the relevant part of the form:
<form action="" method="POST" enctype="multipart/form-data">
            @csrf
                <label for="photos">Photos:</label>
                <input type="file" name="photos[]" id="photos" class="form-control" multiple>
                <button class="btn btn-success mt-3" onclick="ajaxify(event)">Submit</button>
            </div>
        </form>
And here's the relevant part of the javascript:
function ajaxify(event) {
            event.preventDefault();
            let failedValidation = false;
           // I removed parts of the code where I load other dataand do validation, irrelevant to the question.
            let photos = [];
            if(document.getElementById('photos').value !== '') {
                photos = document.getElementById('photos');   // I know this is incorrect, but I don't know what to do here.
            }
           // Here photos.value return something like c://fake/filename
           // And it doesn't return more than 1 file even, so anyway I am definitely doing this wrong.
            if(! failedValidation) {
                axios.post('/listing/create', {
                    client_name: name.value,
                    client_phone_number: client_phone_number.value,
                    category: category.value,
                    type: type.value,
                    governorate: governorate.value,
                    city: city.value,
                    space: space.value,
                    price: price.value,
                    furnished_status: furnished_status.value,
                    payment_type: payment_type.value,
                    initial_deposit: initial_deposit.value,
                    monthly_amount: monthly_amount.value,
                    notes: notes.value,
                    photos: photos.value, // So this should be an array of uploaded files.
                })
                .then((resp) => {
                    invalid.classList.add('d-none');
                    console.log(resp);
                })
            }
        }
What do I want? Is to have the file(s) I uploaded available for Laravel on the server side of the application, when I do a normal post and do dd($request->photos); I get an array of the uploaded files, I'm not sure if that's possible with ajax/json or not, but that's what I want in order to process the photos.
A quick note, I am using the Laravel media library package if that makes any difference.
What I did so far is researching the matter and I read that I need to use FormData(), I've never used that before and I have a couple of questions, do I need to put all of my data inside that FormData() object and feed that to axios? Or do I just need it for the photos? I haven't tried doing any of those two things yet, any guidance will be deeply appreciated.
 
    