Renaming and retyping
was(R, name:, schema:, down:, up:) declares that up to R included, the field had another name, another type, or
both. The head key stays the source: the field is always read under its head key, then renamed and converted.
Rename a field
'status' => Schema::enum(OrderStatus::class)
->was(ApiRevision::Winter25, name: 'state'),
| Client | Response key | Request key | Controller reads |
|---|---|---|---|
spring-26 | status | status | status |
winter-25, genesis | state | state | status |
Query parameters and nested fields are renamed the same way:
'notify' => Schema::bool()->was(ApiRevision::Winter25, name: 'send_email'),
'lines' => Schema::list(Schema::object([
'quantity' => Schema::int()->was(ApiRevision::Genesis, name: 'qty'),
])),
Change a type
schema: gives the older type. Most scalar changes convert automatically; give down: (responses) and up:
(requests) when the automatic cast is not what your clients need, or does not exist. See
Conversions.
'status' => Schema::enum(OrderStatus::class)
->was(
ApiRevision::Genesis,
name: 'paid',
schema: Schema::bool(),
down: fn(OrderStatus $status): bool
=> $status === OrderStatus::Paid,
up: fn(bool $paid): OrderStatus => $paid
? OrderStatus::Paid
: OrderStatus::Pending,
),
down: receives the PHP value of the newer shape, normalized: an OrderStatus case, not 'paid'. It returns the
PHP value of the older shape; serialization comes after. up: mirrors it.
Chained deltas
A field may have several was(). Each describes the shape just before the next newer one, and an argument left out
keeps the value of that newer shape. They are ordered by revision whatever the call order; writing them newest first
reads like the history.
'total' => Schema::int('total_cents')
->was(
ApiRevision::Winter25,
schema: Schema::string(),
down: fn(int $cents): string => number_format($cents / 100, 2, '.', ''),
)
->was(
ApiRevision::Genesis,
schema: Schema::float(),
down: fn(string $amount): float => (float) $amount,
),
| Client | total |
|---|---|
spring-26 | 1250 |
winter-25 | "12.50" |
genesis | 12.5 |
The genesis closure receives what the winter-25 one returned, a string, not the int of the head.
A was() has no source
An older value is always derived from the head value. When it needs more, read the subject given as the second
argument of down:, or declare the old field with until() and its own source next to the new one.