Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

CodeNathan's avatar

File Upload with Inertia and Laravel 12 not working

I am working on using Laravel 12 Inertia and React However the file upload is not working no matter what i do anybody have any idea ? https://github.com/codenathan/invoice/blob/business_settings/resources/js/pages/business-setting/edit.tsx

0 likes
3 replies
LaryAI's avatar
Level 58

The main issue is that Inertia's useForm does not automatically send your request as multipart/form-data (which is required for file uploads) unless you explicitly tell it to. By default, it sends JSON, so your file will not be uploaded.

Solution Steps:

  1. Add enctype="multipart/form-data" to your <form> tag.
  2. Pass { forceFormData: true } as the second argument to patch().

1. Update the <form> tag

Change:

<form className="flex flex-col gap-6" onSubmit={submit}>

to:

<form className="flex flex-col gap-6" onSubmit={submit} encType="multipart/form-data">

2. Update the patch call

Change:

patch(route('business-setting.update', businessSetting.id));

to:

patch(route('business-setting.update', businessSetting.id), {
    forceFormData: true,
});

3. (Optional) Make sure your backend controller handles file uploads

In your Laravel controller, make sure you handle the file upload like this:

if ($request->hasFile('logo')) {
    $path = $request->file('logo')->store('logos', 'public');
    // Save $path to your model, etc.
}

Final Example

<form
    className="flex flex-col gap-6"
    onSubmit={submit}
    encType="multipart/form-data"
>
    {/* ... your fields ... */}
    <Input
        id="logo"
        type="file"
        tabIndex={8}
        accept="image/*"
        onChange={(e) => {
            const file = e.target.files?.[0];
            if (file) setData('logo', file);
        }}
    />
    {/* ... */}
    <Button type="submit" className="mt-4 w-full" tabIndex={4} disabled={processing}>
        {processing && <LoaderCircle className="h-4 w-4 animate-spin" />}
        Update
    </Button>
</form>

And in your submit handler:

const submit: FormEventHandler = (e) => {
    e.preventDefault();
    patch(route('business-setting.update', businessSetting.id), {
        forceFormData: true,
    });
};

Summary:

  • Use encType="multipart/form-data" on the form
  • Use { forceFormData: true } with Inertia's patch
  • Handle file upload in your Laravel controller

This should resolve your file upload issue with Inertia and Laravel 12!

CodeNathan's avatar

The above AI answer did not fix the issue

CodeNathan's avatar
CodeNathan
OP
Best Answer
Level 19

This was answered on stackoverflow, all you need to do is sent the method path within the useForm

  const { data, setData, post, processing, errors } = useForm({
        name: businessSetting.name,
        address_line_1 : businessSetting.address_line_1,
        address_line_2 : businessSetting.address_line_2,
        city : businessSetting.city,
        state : businessSetting.state,
        postal_code : businessSetting.postal_code,
        invoice_footer : businessSetting.invoice_footer,
        logo: null as File | null,
        _method: 'patch',
    });


    const submit: FormEventHandler = (e) => {
        e.preventDefault();
        post(route('business-setting.update', businessSetting.id), {
            forceFormData: true,
        });
    };

Please or to participate in this conversation.