RFC 0086 — Many rows in Laravel: elyraUpdateMany, a set answered by the package
Status: implemented (2026-11-30) · Target: 0.66.0 · builds on RFC 0071 and RFC 0084 · see Decisions
Summary
RFC 0084 lets a desktop table set a column for thousands of rows in calls
of 500: PATCH /api/invoices with { ids, values }, answered { updated, failed }. Over a Laravel backend, make:resource --backend prints an
outline of the controller method, and the app writes it: the validation
of the fields given, each model's policy, a transaction, the answer's
shape. It's the same method in every app, and easy to get subtly wrong
(validating fields that weren't sent, skipping the policy, failing the
whole set for one row).
This RFC puts it in the package, as elyraList (RFC 0071) did for the
list:
public function updateMany(Request $request)
{
return Invoice::query()->elyraUpdateMany($request, [
'rules' => (new UpdateInvoiceRequest)->rules(),
'columns' => ['status', 'due', 'reminded'],
'ability' => 'update',
]);
}
Route::patch('invoices', [InvoiceController::class, 'updateMany']);
Route::apiResource('invoices', InvoiceController::class);
- Only the fields given, and only the
columnsthe controller allows, each validated with its own rules from the update's. - Each row's policy (
$user->can('update', $invoice)), so a user sets only the rows they may. - One transaction for the rows that pass, and the answer the desktop
reads:
{ updated, failed: { id: message } }. make:resource --backendprints the call, not an outline.
Motivation
- RFC 0084 left the server to each app. The desktop side is generated; the Laravel side is a hint, which is where a set of 8,000 rows meets the real policies.
- The same method, written again. Validate the fields given, check each row's policy, update in one transaction, answer in the desktop's shape: none of it differs between resources but the rules and the columns.
- The package already answers lists this way.
elyraListtakes the controller's allowlists and answers the desktop's question; a set is the list's other half.
Current state (0.66)
Builder::macro('elyraList', …)answers a desktop list (RFC 0071).- A desktop
{p}_update_manyover a backend sendsPATCH {path}with{ ids: [...], values: { column: value } }, only the fields given (RFC 0084); it reads{ updated, failed: { id: message } }. make:resource --backendprints, for it: "a method that validates the givenvalueswith the update rules, updates each row the user may update in a transaction, and answers{ updated, failed }".
Design
->elyraUpdateMany($request, $options)
A Builder macro, on the query the rows are found through (so a scope,
a tenant, soft deletes apply):
| Option | ||
|---|---|---|
rules |
array |
The update's rules, by field: only the ones for the fields given are used. |
columns |
string[] |
The fields a set may change. Anything else in values is refused, the whole request (a 422 for the field). |
ability |
string|null |
The policy ability checked per row ('update' by default); null skips it. |
max |
int |
The most ids a request takes (500, RFC 0084's chunk); more is a 422. |
What it does:
- The request:
ids(a list of keys, at mostmax) andvalues(an object of the allowedcolumns). Anything else is a 422. - The values, validated once, with their rules from
rules(auniquerule for more than one id is a 422: it can't be unique for many), as Laravel's validator does a request, so the 422 is the one a form gets. - The rows:
whereKey($ids)on the query. A key not found isfailed("not found"); a row the policy refuses isfailedwith the policy's message. - The write: in one transaction, each passing model's
fill($values) ->save(), so its events, casts andupdated_atwork; or, with'quietly' => true, oneupdate()on their keys without events. - The answer:
{ "updated": 238, "failed": { "12": "This invoice is locked." } }, 200.
make:resource --backend
The hint prints the route and the method with elyraUpdateMany, its
columns the fields a patch sets (RFC 0084's patchable), and rules
from the resource's update request when it has one.
The guide
docs/backend.md gets "Many rows at once", beside "Lists searched,
filtered and totalled", with the request, the answer and the options.
Implementation plan
laravel/src/Lists/ElyraUpdateMany.php: the request's checks, the values' validation, the rows, the policy per row, the transaction, the answer; theBuildermacro in the service provider.- The test app the Laravel CI job builds: a route and a policy that
use it, and
framework/tests/laravel_update_many.rsagainst it: only the given fields and the allowed columns, a refused column, a unique rule for many,max, a key not found, a policy that refuses one row, the events by default andquietly, a scope on the query respected, the answer's shape, and a desktop{p}_update_manythrough it. ratatosk: the hint's method withelyraUpdateMany.- Docs:
backend.md,laravel/README.md,resources.md, the Laravel backend skill, CHANGELOG.
Open questions
fill()->save()per row, or oneupdate()? Recommendation: per row, by default, in one transaction: a model's events, observers, casts andupdated_atare what an app relies on, and 500 saves in a transaction are quick.'quietly' => truefor a table that wants the one statement.- A refused column: the whole request, or the field left out? Recommendation: the whole request, a 422. The desktop sends what the user set; silently dropping it would say "set" for a value that wasn't.
- The policy per row, or
viewAny-style once? Recommendation: per row, asupdatechecks one model: a policy that depends on the record (its owner, its state) is the common one.
Decisions
Accepted 2026-11-30, with the open questions' recommendations:
fill()->save()per row in one transaction by default;'quietly' => truefor oneupdate().- A column not allowed refuses the request, a 422 for the field.
- The policy per row.
As built
As designed, with these differences:
- Each row is saved with
forceFill(), notfill(): thecolumnsare the controller's allowlist, so a column that isn't in$fillablebut is allowed here is set. - The answer's keys are the ids as text (JSON object keys), as the desktop reads them.
- The hint's rules are the resource's own, each
sometimes|, since a patch gives only some fields; an app with aFormRequestpasses itsrules()instead. - Tested against the test app the Laravel CI job builds: a
PATCH /api/customersroute, aCustomerPolicy::updatethat refuses a locked customer and a user withoutcustomers.update, andframework/tests/laravel_update_many.rs, a step of its own in the job.quietlyisn't exercised there.
Not in this RFC
- Deleting many rows in one request (
elyraDestroyMany). - A job for sets larger than a request (queued, with progress over broadcasting).
- Different values per row (a paste) in one request.
Alternatives considered
- Keep the hint. Every app writes the same method, and the policy per row is the step most likely to be left out.
- A controller trait (
use ElyraUpdatesMany). It ties the method's name and route to the package; a macro on the query lets the app keep its controller and its scopes.