Concepts
Field conditions
Field conditions let a collection field change visibility, readonly, or required based on other field values on the same item. Form UX (client) and server enforcement for required / readonly stay in sync.
Sources of truth
PHP: App\Services\Collections\FieldConditionEvaluator. TS: resources/js/lib/field-conditions.ts. Settings UI: field settings → Conditions. Stored under collections_fields.settings.conditions.
Shape
{
"logic": "and",
"rules": [{ "field": "status", "operator": "equals", "value": "published" }],
"hidden": false,
"readonly": true,
"required": true
}
| Key | Meaning |
|---|---|
logic | and (default) — all rules must match; or — any rule matches |
rules | Flat list of { field, operator, value? } (no nested groups) |
hidden | When matched: hide field. Explicit false = show-when (hide unless matched) |
readonly | When matched: lock field (server strips writes) |
required | When matched: require a value (server validation) |
Existing AND / equals rules keep working unchanged.
Operators
| Operator | Value | Match when… |
|---|---|---|
equals | any | Loose string equality (arrays: contains expected); booleans tolerate 0/1 |
not_equals | any | Negation of equals |
contains | string / number | String substring, or array membership |
empty | — | null, blank string, or [] |
not_empty | — | Negation of empty |
gt / gte / lt / lte | number or ISO date prefix | Numeric compare, or lexicographic ISO YYYY-MM-DD… |
in | comma list or array | Actual (or any array element) is in the list |
not_in | comma list or array | Negation of in |
Examples
Show notes only when kind is custom (show-when):
{
"logic": "and",
"rules": [{ "field": "kind", "operator": "equals", "value": "custom" }],
"hidden": false
}
Require price when status is draft or review (OR + in):
{
"logic": "or",
"rules": [
{ "field": "status", "operator": "equals", "value": "draft" },
{ "field": "status", "operator": "in", "value": "review, pending" }
],
"required": true
}
Lock title after publish date is set (gte):
{
"logic": "and",
"rules": [
{ "field": "published_at", "operator": "gte", "value": "2020-01-01" }
],
"readonly": true
}
Kitchen Sink sketch
On a demo collection with kind (select), status (select), amount (number), notes (string):
- Hide
notesunlesskindequalscustom. - Require
amountwhenstatusisindraft, revieworamountgt0is not enough alone — prefer one rule set per effect. - Readonly
statuswhenpublished_atisnot_empty.
Out of scope
No Flow builder, no HTTP / external conditions, no nested rule groups. Extend via Extending if you need that.
Related