Updating data
Update one document
Retrieve a result object, then call update() with fillable fields:
$user = User::findOrFail('user-123');
$result = $user->update([
'age' => 30,
'status' => 'active',
]);
Version 4.0 sends a Firestore update mask. Fields omitted from the array are preserved, including fields omitted by a previous select() query. The primary key cannot be changed.
Update many documents
$updated = User::updateMany([
['id' => 'user-1', 'status' => 'active'],
['id' => 'user-2', 'status' => 'inactive'],
]);
Each item must include the model primary key. Other fields must be fillable. The method returns the number of requested writes and uses Firestore commit groups of at most 500 updates.
Each group is atomic. More than 500 updates are split into multiple commits and are not globally atomic.