Validation
Overview
Validation rules may be added to any field.
In Laravel, validation rules are usually defined in arrays like ['required', 'max:255']
or a combined string like required|max:255
. This is fine if you're exclusively working in the backend with simple form requests. But Filament is also able to give your users frontend validation, so they can fix their mistakes before any backend requests are made.
Filament includes several dedicated validation methods, but you can also use any other Laravel validation rules, including custom validation rules.
Beware that some validations rely on the field name and therefore won't work when passed via
->rule()
/->rules()
. Use the dedicated validation methods whenever you can.
Available rules
Active URL
The field must have a valid A or AAAA record according to the dns_get_record()
PHP function. See the Laravel documentation.
Field::make('name')->activeUrl()
After (date)
The field value must be a value after a given date. See the Laravel documentation.
Field::make('start_date')->after('tomorrow')
Alternatively, you may pass the name of another field to compare against:
Field::make('start_date')
Field::make('end_date')->after('start_date')
After or equal to (date)
The field value must be a date after or equal to the given date. See the Laravel documentation.
Field::make('start_date')->afterOrEqual('tomorrow')
Alternatively, you may pass the name of another field to compare against:
Field::make('start_date')
Field::make('end_date')->afterOrEqual('start_date')