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.
| Rule | Behavior |
|---|---|
required | Value must be present and not empty. |
nullable | Allows null or empty string and skips other rules. |
string | Value must be a string. |
integer | Value must pass integer validation. |
numeric | Value must be numeric. |
boolean | Value must be true, false, 0, 1, "0", or "1". |
array | Value must be an array. |
email | Value must be a valid email address. |
url | Value must be a valid URL. |
confirmed | Value must match <field>_confirmation. |
same:field | Value must match another field. |
in:a,b | Value must be one of the listed scalar values. |
min:n | Minimum number, string length, or array count. |
max:n | Maximum 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.