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

fulufhelo's avatar

Updating the image in laravel 8 clears out the rest of the data in the form

I am working on a laravel 8 project, am using Vue and Inertia when i try to update an image it clears the rest of the data in the form. But if i update the the form without updating the image it works fine. I can create a new record with an image i find that only when i try to update the image that's when this happens

0 likes
2 replies
automica's avatar

Can you show some code for the method that create your new record?

faaizhr's avatar

Uploading files using a multipart/form-data request is not natively supported in some languages for the PUT,PATCH, or DELETE methods. The simplest workaround for this limitation is to simply upload files using a POST request instead.

However, some frameworks, such as Laravel and Rails, support form method spoofing, which allows you to upload the files using POST, but have the framework handle the request as a PUT or PATCH request. This is done by including a _method attribute in the data of your request.

For Example Now, your code may like this

Inertia.put(`/posts/${props.post.id}`, {
                  title: title,
                  content: content,
                  image: image,
            })

You should change into

      Inertia.post(`/posts/${props.post.id}`, {
                  _method: 'put',
                  title: title,
                  content: content,
                  image: image,
            })

Please or to participate in this conversation.