Fields
The FormField model, its 27+ field types, validation, conditional logic and dynamic option sources.
Overview
The FormField model represents an individual form input. Polyform ships with 27+ field types, from simple text inputs to matrix grids and repeatable field groups. Fields support validation, conditional visibility, nesting and both static and dynamic option sources.
Field Types
The FieldType enum defines 27+ string-backed types, each with behavior methods:
hasOptions(), isNumeric(), isDate() and isDisplay() to check capabilities without manual type checking. Core Properties
Creating Fields
The FormBuilder has convenience methods for every field type or you can create fields directly through relationships:
Field Settings
Each field type has its own settings stored as JSON. Here are some common examples:
$field->resolved_settings to get merged defaults + custom settings for the field type. Conditional Logic
Fields can be shown or hidden based on other field values:
Conditions are evaluated on the frontend via the useFieldConditions composable and on the backend during validation.
Validation Rules
Fields store Laravel validation rules that run during submission:
The FieldValidatorFactory maps each FieldType to its validator class. You can register your own validators through the factory.
Option Sources
Select, radio, checkbox and similar fields can pull options from multiple sources:
- Static options - Stored as FormFieldOption records
- Enum options - Loaded from PHP enums via
cases() - Model options - Queried from Eloquent models
- Resolver options - Generated by custom resolver classes
/polyform/option-sources API endpoint, which supports listing, searching and resolving by value. Relationships
- form - BelongsTo Form (parent form)
- step - BelongsTo FormStep (parent step for multi-step forms)
- parent - BelongsTo FormField (parent field for nested structures)
- children - HasMany FormField (child fields for repeaters)
- options - HasMany FormFieldOption (static options)
Nested Field Structures
Repeater fields can contain nested child fields for more complex data:
The frontend PolyformRenderer handles nested field rendering and validation automatically using provide/inject.
Computed Attributes
- has_dynamic_options - Whether options are loaded dynamically
- resolved_settings - Merged field type defaults with custom settings
Extensibility
You can register custom field validators, option resolvers and field types through the package config and service provider bindings.