Laravel How to update multiple records using request all
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
# Laravel: Mastering Bulk Updates with Request Data and Eloquent
As a senior developer working with Laravel, one of the most common tasks we face is managing data in bulkâwhether inserting many records or updating several existing ones based on user input. While methods like `create()` are perfectly suited for inserting new models, shifting gears to mass updates using `$request->all()` often presents a hurdle. The difference lies in how Eloquent handles creating versus updating operations, especially when dealing with multiple entries simultaneously.
This post will dive into why your update attempt might be failing and provide the correct, efficient patterns for updating multiple records in Laravel.
## Understanding the Difference: Create vs. Update
The reason your insertion method works but your update method struggles is rooted in how Eloquent handles model instantiation and saving.
When you use `$model::create($attributes)` (as in your working example), Eloquent knows exactly which single model to create, maps all the provided attributes, and saves it in one go.
However, when you try to update multiple records, especially if you are expecting a single model instance (`$teacher`) to be updated via `$teacher->save()`, Laravel is designed around fetching a specific record by its ID. Passing an entire array of request data doesn't automatically map to the existing model instance in a straightforward manner for mass updates.
## The Correct Approach: Mass Updating Records
To effectively update multiple records from a single request, you need to shift your focus from saving a single model instance to interacting directly with the database query builder or leveraging collection methods. This is much more efficient and scalable than looping through individual saves.
### Method 1: Using `update()` for Specific Models
If the request contains data for *one* specific record (identified by an ID), you should use the Eloquent `update()` method directly on that model instance, passing the data payload.
```php
public function update(Request $request, Teacher $teacher)
{
// Ensure the route binding provides the correct teacher instance
$teacher->update($request->only(['name', 'email', 'phone']));
return back()->with('message', 'Record Successfully Updated!');
}
```
Notice how we use `$request->only([...])` to safely extract only the fields we intend to change, adhering to good security practice. This is a core principle of secure data handling in Laravel, which you can find detailed explanations for on the official documentation at [https://laravelcompany.com](https://laravelcompany.com).
### Method 2: Handling Multiple Records (Bulk Update)
If your goal is to update *many* records based on an array sent from the client, iterating through the request data and using mass assignment is the most robust approach. This pattern avoids unnecessary database queries within a loop significantly improving performance.
For bulk operations, we typically load the data into an array of models first and then save them.
```php
use App\Models\Teacher;
use Illuminate\Http\Request;
public function bulkUpdate(Request $request)
{
// Assume $request->input('teachers') returns a JSON or array structure
// containing the data for multiple teachers to update.
$teacherData = $request->input('teachers', []);
foreach ($teacherData as $data) {
// Find the teacher by ID, then update it using the provided data.
// This assumes $data contains the primary key ID.
$teacher = Teacher::findOrFail($data['id']);
// Use the mass update method for efficiency
$teacher->update($data);
}
return back()->with('message', 'Multiple Records Successfully Updated!');
}
```
This pattern ensures that you are explicitly querying and updating existing records, which is fundamentally different from the `create()` operation. When dealing with complex data interactions like this, understanding Eloquent's scope and methods is crucial for writing clean, performant code. For deeper insights into Eloquent relationships and query management, exploring resources on [https://laravelcompany.com](https://laravelcompany.com) is highly recommended.
## Conclusion
In summary, while `$request->all()` is powerful for gathering input data, it does not inherently translate to a bulk update operation in the same way as `create()`. For updating existing records, developers should rely on Eloquent's specific methods: use `$model->update($data)` for single updates or loop through your request data and utilize `findOrFail()` followed by `update()` for performing safe, efficient bulk modifications. Mastering these distinctions will lead to cleaner, faster, and more maintainable Laravel applications.