Cmd/Ctrl + K

Validation

Annabel includes a small validation layer for request and configuration data.

Validate data

Create a validator from input data and the rules each field must satisfy.

Controller validation

Use the controller trait to validate request data and return standard failure responses.

Validation failures return JSON 422 responses for API requests or redirect back with flashed errors for web forms.

Available rules

Rules can be combined to express presence, type, format, and size constraints.

RuleBehavior
requiredValue must be present and not empty.
nullableAllows null or empty string and skips other rules.
stringValue must be a string.
integerValue must pass integer validation.
numericValue must be numeric.
booleanValue must be true, false, 0, 1, "0", or "1".
arrayValue must be an array.
emailValue must be a valid email address.
urlValue must be a valid URL.
confirmedValue must match <field>_confirmation.
same:fieldValue must match another field.
in:a,bValue must be one of the listed scalar values.
min:nMinimum number, string length, or array count.
max:nMaximum number, string length, or array count.

Nested fields

Rules may use dot notation:

Validated data

Read only fields that passed validation before persisting or processing input.

Use validateOrFail() when an exception-driven flow is clearer:

Custom rules

Register a custom rule when validation cannot be expressed by the built-in set.

Custom validators return null for success or an error message for failure.