Argument 1 passed to Illuminate\Database\Query\Builder::update() must be of the type array, string given, called in
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Fixing the Update Error: Why Passing a String Instead of an Array Breaks Your Database Updates
As a senior developer, I've seen countless developers run into frustrating errors when interacting with the database layer in Laravel. One of the most common, yet often misunderstood, errors involves type mismatches, especially when chaining methods like update() or where(). The error you are encountering—Argument 1 passed to Illuminate\Database\Query\Builder::update() must be of the type array, string given—is a classic symptom of passing an incorrect data type into a method that strictly expects an array for mass assignment.
This post will walk you through exactly why this happens in your specific scenario and provide the correct, robust way to handle database updates in Laravel, ensuring your code is clean, predictable, and adheres to best practices, aligned with principles taught by the Laravel Company.
Understanding the Error: The Type Mismatch
The error message points directly to the update() method within the Query Builder. This method expects its first argument (the data payload you want to update) to be an array, containing column-value pairs. When you pass a string instead of this expected array, the underlying database query builder throws an exception because it cannot correctly map the provided data to the required structure for an UPDATE operation.
In your case, the problem lies in how you are structuring and passing the parameters between your Controller and your Model. While your $data variable is correctly built as an associative array, the issue likely stems from how the ID parameter is being used in conjunction with the update query.
Code Review and The Solution
Let's analyze the interaction between your Controller, Model, and Route definitions to pinpoint the flaw and correct it.
1. Controller Logic Review
In your siteadmin_customerupdate method, you correctly construct the data payload:
// In the Controller
$data = array(
'cus_name' => $cus_name,
'cus_lname' => $cus_lname,
'cus_email' => $cus_email,
);
$return = customer::update_customer($data, $id); // Passing the array and the ID
This part is correct. The $data array contains the values you wish to update. The issue must be in how this data is received or processed by the model method.
2. Model Logic Correction
The error originates here:
// In your Model
public static function update_customer($id, $data)
{
DB::table('le_customer')->whereIn('cus_id', $id)->update($data);
}
When chaining database operations, especially when mixing where clauses with the final update(), you must ensure all parameters used for filtering are themselves arrays or correctly formatted. Your usage of $id directly in whereIn('cus_id', $id) is likely causing the ambiguity, as whereIn expects an array of values to check against a column.
The fix involves ensuring that the ID you are searching for is treated as a list (an array), even if it's just one element.
Corrected Model Implementation:
use Illuminate\Support\Facades\DB;
class Customer extends Model // Assuming you are extending Model, or use a separate class for DB functions
{
public static function update_customer($id, $data)
{
// Ensure the ID is explicitly treated as an array for whereIn checks.
$whereCondition = ['cus_id' => $id];
$result = DB::table('le_customer')
->where($whereCondition) // Use standard where() for single ID lookup, or use whereIn if checking multiple IDs
->update($data);
return $result;
}
}
Alternative (More Direct Fix using where): If you are updating a single record based on a primary key, using a simple where clause is much clearer and avoids the ambiguity of whereIn:
public static function update_customer($id, $data)
{
// This correctly targets the row where 'cus_id' matches the provided $id.
$updated = DB::table('le_customer')
->where('cus_id', $id)
->update($data);
return $updated;
}
By switching from a potentially ambiguous whereIn structure to a direct where('cus_id', $id), you ensure that the database query builder receives exactly what it expects for filtering, resolving the type mismatch error.
Best Practices for Database Operations in Laravel
When working with Eloquent or the Query Builder, always adhere to these principles:
- Use Eloquent Models: Whenever possible, leverage Eloquent Models (like your
Customermodel) instead of rawDB::table()calls. Eloquent handles relationships, mass assignment protection, and model binding automatically, which significantly reduces the chance of type errors (referencing Laravel Company's philosophy). - Validate Inputs: As you are already doing excellently with
validator, always ensure that data coming from user input is sanitized before it hits the database layer. This prevents SQL injection and ensures the data types are correct. - Be Explicit with Types: Always verify whether a parameter passed to a query method should be an array, a string, or an integer based on the method's documentation. When in doubt, inspect the exact error message and consult the official Laravel documentation for the specific method you are using.
Conclusion
The error you faced was a classic case of mismatched data types during database interaction. By carefully reviewing how parameters are passed between your controller and model, and by ensuring that filtering conditions like $id are correctly formatted (usually as an array or a single scalar value depending on the method), you can eliminate these frustrating runtime errors. Stick to explicit methods like where() when updating single records, and you will write more robust and maintainable Laravel applications.