Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
Multiple file upload with laravel and vue 3

I am trying to upload multiple files with laravel and vue 3. I have 3 attributes user_files, book_files[]

 <input
            type="file"
            class="form-control"
            name="user_files[]"
            @change="onFileChange"
            multiple
            id="user_files"
            placeholder="User details"
          />
        </div>

  const form = reactive({
  first_name: "",",
  hourly_rate: 0,
  user_files: [],
  book_files: []
  user_name: "",
  course_date: "",
});


const onFileChange = (e) => {
  for (let i = 0; i < e.target.files.length; i++) {
    form.user_files.push(e.target.files[i]);
  }
 };

const { errors, storeUser } = useUsers();

const saveUser = async () => {
  await storeUser({ ...form });
};

return {
  form,
  saveUser,
  onFileChange,
};

How can I rewrite the function onFileChange for multiple attributes, right now it is only for `user_files.

 const storeUser = async (data, medical_file) => {  
let formData = new FormData();
(data.user_files ?? []).forEach((file, key) => {
  formData.append("user_files[]", file);
});;

    errors.value = "";
    try {
      const status = await http.post("/api/users", formData, formData, {
        headers: {
          "Content-Type": "multipart/form-data",
        },
      });

Also in above js function, I need to append rest of the data like first_name, user_name and others into the formData as well, and loop over the other files along with user_files. How should I do that (data.medical_file ?? []).forEach((file, key) => { formData.append("medical_file[]", file); });; in this function.

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!