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:
- Add
enctype="multipart/form-data"to your<form>tag. - Pass
{ forceFormData: true }as the second argument topatch().
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'spatch - Handle file upload in your Laravel controller
This should resolve your file upload issue with Inertia and Laravel 12!