DEV Community

Manjeet Singh
Manjeet Singh

Posted on • Originally published at codermanjeet.Medium on

Enums: How Laravel Devs Cut bugs by 50%

Enums: How Laravel Devs Cut bugs by 50%

You are building your Laravel app with Inertia.js, everything works perfectly until you try to update a record with a file upload. Text fields update fine, but files mysteriously vanish into thin air. Sound familiar?

This is one of the most frustrating bugs Laravel developers face when working with Inertia.js. The good news is that you are not alone and there are proven solutions. Let me walk you through the 5 most common issues with PUT and PATCH file uploads and exactly how to tackle each one.

The Root Cause Behind the Mystery

Before diving into solutions, you need to understand why this happens. PHP and many server-side frameworks do not natively process multipart/form-data requests for PUT, PATCH, or DELETE methods. This limitation exists at the PHP core level, not in Laravel or Inertia itself.

When you send a file using PUT or PATCH, PHP simply cannot parse the incoming FormData object the same way it does for POST requests. The data arrives at your server but remains unparsed in the raw input stream.

Issue 1: Files Not Received in Laravel Controller

This is the classic problem. You submit your form with a file using form.patch() and when you dump the request in your controller, the file is null or missing entirely.​

Here is what typically fails:

const form = useForm({
  name: 'Product Name',
  image: null
})

function update() {
  form.patch(route('products.update', product.id))
}
Enter fullscreen mode Exit fullscreen mode

In your Laravel controller, request file image returns null even though you selected a file.​

The Solution:

Use method spoofing by switching to POST and adding the underscore method field. Laravel recognizes this pattern and treats your request as PUT or PATCH.​

import { router } from '@inertiajs/vue3'

const form = useForm({
  _method: 'put',
  name: 'Product Name', 
  image: null
})

function update() {
  form.post(route('products.update', product.id))
}
Enter fullscreen mode Exit fullscreen mode

Alternatively, use the router directly:

router.post(`/products/${product.id}`, {
  _method: 'put',
  name: form.name,
  image: form.image
})
Enter fullscreen mode Exit fullscreen mode

This workaround leverages Laravel’s built-in method spoofing support, which checks for the underscore method field and routes your request correctly.

Issue 2: Empty Request Data with FormData

Sometimes the entire request arrives empty when you use PUT or PATCH with files. Your request all returns an empty array and even text fields go missing.​

Continue reading on Medium »

Top comments (0)