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

AlthafBudiman's avatar

Error File Upload Update In Inertia React

So i try to create a update thumbnail feature with Inertia React, and this is the code:

ArticleItem: const { data, setData, patch, errors, reset, processing } = useForm({ thumbnail: article.thumbnail })

function onSubmitThumbnailChangeHandler(e) {
    e.preventDefault()
    console.log(data.thumbnail)
    patch(`/articles/${article.id}/editThumbnail`, { onSuccess: () => reset() })
}
                            {errors.thumbnail &&
                                <p className="mt-2 text-sm text-red-700">{errors.thumbnail}</p>
                            }

                            <div className="justify-end flex gap-3 mt-6">
                                <button type="submit" disabled={processing} className={`mt-4 w-full py-2 px-4 bg-darkerBlue rounded-lg text-white ${processing && 'opacity-25'}`}>Save</button>
                            </div>
                        </form>

ArticleController: public function updateThumbnail(Request $request, Article $article) { $validated = $request->validate([ 'thumbnail' => 'required|mimes:png,jpg,jpeh' ]);

    $article->update($validated);
    return redirect('/admin');
}

When i try to upload the file then submit it there's an error: thumbnail field is required

What happen??? please help thank you

0 likes
4 replies
gych's avatar

Does this console log show the expected thumbnail ?

 console.log(data.thumbnail)
AlthafBudiman's avatar
AlthafBudiman
OP
Best Answer
Level 1

nevermind i've solved it

const { data, setData, post, errors, processing } = useForm({ thumbnail: article.thumbnail, _method: 'patch' })

function onSubmitThumbnailChangeHandler() {
    console.log(data.thumbnail)
    post(`/articles/${article.id}/editThumbnail`)
}
gych's avatar

@AlthafBudiman Good that you've managed to solve it already. Please don't forget to close your thread by marking your solution as best answer.

1 like

Please or to participate in this conversation.