PATCH and PUT Request Does not Working with form-data
Stefan Izdrail
Founder & Senior Architect · 2026-06-29
Title: Understanding PATCH and PUT Request Issues with Form-Data in Laravel Applications
Body:
In the past few years, RESTful APIs have become the foundation of modern web applications. As such, working with HTTP methods like PATCH or PUT to update existing resources is an essential practice for developers. However, when using form-data to send these requests in tools like Postman, you may encounter issues that prevent your parameters from reaching the server as expected.
- HTTP Requests and Form-Data: Before discussing the specific issue, it's essential to understand how HTTP requests work with form data. When using form-data, each parameter is sent in a separate key-value pair, encoded as name=value pairs separated by ampersand characters (e.g., testimonial=some_value&user_id=123).
- Handling Form-Data with PATCH and PUT: Laravel's default behavior for updating existing resources uses the HTTP methods PATCH or PUT, which are intended to update specific fields of a resource. When you use these methods in your routes (as shown earlier), you would typically pass the new values through the URL like this:
http://example.com/api/testimonials/{testimonial}/update?testimonial=new_value&user_id=123. In this case, you can use Laravel's built-in HTTP method validation to ensure that the proper fields are sent and updated. - The Issue with Form-Data: The problem arises when you try to send form-data in a PATCH or PUT request. When Postman encounters multiple parameters, it sends them as individual key-value pairs instead of using the default x-www-form-urlencoded format (name1=value1&name2=value2). This encoding is not supported by Laravel's default form data processing and might result in an empty $request->all() array when you try to access your parameters on the server side.
- Implementing a Workaround: To resolve this issue, one option is to adapt your code to use standard x-www-form-urlencoded encoding instead of form-data. This can be achieved by adding the following header before sending your request in Postman:
Headers -> Key: Content-Type | Value: application/x-www-form-urlencoded. Alternatively, you could use the Laravel API tooling to validate and sanitize incoming requests, ensuring that they are encoded correctly. - Alternative Solutions: As a final note, consider using the POST method instead of PATCH or PUT for updating resources. This would allow you to use form-data without causing any issues on the server side while still adhering to RESTful principles.