How to use patch request in Laravel?

How to use patch request in Laravel?

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Handling PATCH Requests in Laravel: Semantics, Validation, and Routing

In RESTful architectures, the PATCH method serves a specific purpose distinct from PUT. While PUT implies a full replacement of a resource, PATCH is designed for partial updates. This distinction becomes critical when managing entities like a User where certain fields are optional or stored as NULL by default. If you attempt to update only specific columns—such as changing a user's city or region without altering their name or email—you must ensure your backend logic respects this partial nature.

Your current routing setup defines a dedicated endpoint:

Route::patch('users/update', 'UsersController@update');

While functional, this route definition suggests an imperative action ("update me") rather than a resource-based approach. In standard Laravel conventions, routes often follow the pattern of Route::patch('users/{user}', ...). However, if your application requires a specific action name like /users/update, the current structure is acceptable, provided you handle the parameters correctly in the controller.

Controller Logic and Partial Updates

The core challenge with PATCH requests lies in how Laravel handles the input data versus what the database update statement actually executes. In your controller implementation, you are using the $request->all() method for validation but accessing specific properties like $request->name directly within the query builder.

There is a significant semantic difference here. When you pass User::where("user_id", $id)->update([...]), Laravel's Eloquent ORM updates only the fields explicitly provided in the array. If your client sends a JSON payload containing only "city": "New York", the update operation will touch only that column. Fields like name or surname will remain untouched in the database, preserving their current values (even if they are NULL). This is the intended behavior of a partial update.

However, your validation rules currently enforce required constraints on fields like "name" and "surname". This creates a logical conflict for a true PATCH request. If a client wishes to update only their phone number but leaves their name blank in the payload (or omits it entirely), your validator will reject the request because name is marked as required.

To support partial updates correctly, you should decouple validation from the full schema. You might consider making fields optional during validation or using a custom rule that checks if the field exists before enforcing constraints. Alternatively, if your business logic dictates that certain fields must always be present in every update request regardless of the HTTP method, then treating it as a PATCH for partial updates is technically incorrect; you would instead need to accept those fields as mandatory inputs.

Routing Parameters and the $id Argument

Regarding your question about passing the $id parameter: Yes, the route must receive an identifier to determine which record to modify. In your current routing definition:

Route::patch('users/update', 'UsersController@update');

You have not defined a parameter placeholder in the URL pattern. Consequently, when you call update($request, $id) in your controller, Laravel will not automatically inject $id unless you pass it explicitly (e.g., via query string) or define the route with a segment like {id}.

It is best practice to include the ID directly in the route definition:

Route::patch('users/{user}', ['uses' => 'UsersController@update']);

This allows you to extract the $user (or $id) from the route parameters automatically within your controller method signature. This approach aligns with Laravel's routing conventions and ensures that the where("user_id", $id) clause in your query builder receives the correct value without manual intervention.

Best Practices for Partial Updates

When designing handlers for PATCH requests, always verify whether the application logic allows omitting fields. If a field is intended to be updated only when present in the request, ensure your validation rules reflect that flexibility. For instance, instead of 'required|integer', you might use a custom validation rule or check existence before applying constraints.

Additionally, be cautious with unique constraints on fields being partially updated. In your code, "email_work" is validated as unique:users. If this field can already exist on the record but you are only updating other columns, the uniqueness check will pass fine. However, if you are updating the email itself, ensure you exclude the current user from the uniqueness check to avoid false positives during self-updates.

For more complex scenarios involving nested updates or dynamic fields, consider leveraging Laravel's built-in partial update capabilities by ensuring your payload structure matches exactly what the update() method expects. This keeps your API predictable and adheres to RESTful standards where possible.

Our network