Laravel rules
Every parameter which is not an admin parameter is passed to the Laravel validator as a rule, soemail, url, in:a,b, unique:table,column or regex:/pattern/ work as they are.
Model::validator().
Required fields
required makes the field mandatory. The column is created as NOT NULL and the form shows an asterisk. Every optional field gets the nullable rule automatically.
- A required
date,timeorfilefield refuses an empty value, although these types are nullable by default. - A required
fileis not required again when editing a record which already has a file, only after the file is removed. - A required
localefield requires only the default language. requiredis skipped in the admin form forremoveFromFormanddisabledfields, their posted value is ignored as well.hideOnCreateonly hides the input, a required field is still validated when creating.- When a field becomes
requiredand the existing column containsNULLvalues,admin:migratekeeps the column nullable and prints a warning. - In array notation use a real boolean,
'required' => falsekeeps the field optional.
Nullable column
null creates a nullable column even for a required field. Use it when records are created from code without the value, while the admin form still requires it.
Length and value limits
Maximum length of a text, maximum value of a number or maximum size of a file in kilobytes. On
string and select fields it also sets the column length, max:1000 creates varchar(1000). String fields have max:255 by default.On a multiple select it limits the number of selected values in the form, on multiple files it limits the size of every file.name:Perex|type:text|max:500Minimum length of a text or minimum value of a number.
min:0 on integer and decimal fields creates an unsigned column, a negative minimum keeps it signed.name:Balance|type:integer|min:-100Shortcut for
min:0, negative values are refused and the column is unsigned. A min written on the field wins.name:Stock|type:integer|unsignedConditional required rules
Laravelrequired_if, required_unless, required_with and required_without rules work as usual. The form shows the asterisk dynamically by the current values of the other fields. required_with_all and required_without_all are validated, but without the asterisk.
Password confirmation
confirmed adds a second input {key}_confirmation below the field, both values must match. An empty password on edit is ignored, so the password stays unchanged.
File extensions
extensions lists the allowed file extensions of a file field. The file content must match one of the listed types as well. With multiple every file is checked.
Unique value in a JSON column
unique_json checks that a value is unique inside a JSON column. For locale fields each language is checked separately.
Parameters: table,column,exceptId,exceptColumn,column,value…. column->key compares a fixed JSON key.
Partial updates
A checkbox withsometimes which is missing in the request is not reset to 0 by Model::validator()->getData(), so partial API updates keep its value. The admin form always sends unchecked checkboxes as 0.
Arrays and multiple values
multiple and multirows add the array rule. Rules of multiple file, date and time fields are applied to every item (images.*).
Date types validate values with date_format_multiple, which passes when the value matches any of the listed formats (d.m.Y, Y-m-d and the ISO strings sent by the date picker). You can replace the list for a custom input: