How to use patch request in Laravel?

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Efficiently Utilizing PATCH Requests in Laravel Applications Body: In a modern Laravel application, you may encounter situations where updating specific fields from an entity stored in a database is necessary. In such cases, using the HTTP PATCH method can be highly effective while maintaining data integrity and efficiency. This blog post aims to provide a comprehensive guide on how to use PATCH requests in Laravel applications. 1. Creating the Route: Firstly, you'll need to set up the appropriate route for handling patch requests. In your routes file, add this line of code:
Route::patch('users/update', 'UsersController@update');
This route registers a PATCH method called "users/update" that directs to the UsersController@update method when requested. 2. Developing the Controller: Next, you need to write your controller class to handle patch requests and perform data-updates accordingly. Your updated controller should look like this:
public function update(Request $request, $id)
    {
        // Validate incoming request data
        $validator = Validator::make($request->all(), [
            "name" => 'required|string|min:3|max:50',
            "email_work" => 'email|max:255|unique:users',
            "surname" => 'required|string|min:3|max:50',
            "tel" => 'required|numeric|size:11',
            "country" => 'required|integer',
            "region" => 'required|integer',
            "city" => 'required|integer'
        ]);

        if (!$validator->fails()) {
            // Update data from Users table
            $user = User::where('user_id', $id)->update([
                "name" => $request->name,
                "surname" => $request->surname,
                "tel" => $request->tel,
                "country" => $request->country,
                "city" => $request->city,
                "region" => $request->region,
                "email_work" => $request->email_work
            ]);

            // Return the updated user object as JSON response
            return response()->json(["user" => $user], 200);
        } else {
            return response()->json(["message" => $validator->errors()->all()], 400);
        }
    }
In this example, you first validate the input data using Laravel's Validator class. After validating the incoming request, you proceed to update the specified fields of your entity stored in the table Users. Finally, return a JSON response with either the updated user object or an error message based on validation results. 3. Using ID Parameters: It is essential to pass the ID parameter of the entity to your routing and controller for efficient data updating. In Laravel, you can use a relative route for this purpose. For instance, if your PATCH request targets a user with an ID of 12, you would send a request to "/users/update/12" to update its specific fields. 4. Handling PATCH Requests: When handling PATCH requests in Laravel, make sure that only the required fields are updated while leaving others untouched. This ensures data consistency and minimizes potential errors. It is also crucial to handle validation and error-checking appropriately within your controller. To summarize, efficiently utilizing PATCH requests in a Laravel application requires setting up proper routing, preparing the appropriate controller methods, handling ID parameters, and ensuring necessary validations and error-handling. By following these steps, you can effectively manage data updates while maximizing efficiency and data integrity within your web app.