Fields
Overview
Every field starts with make(), and shares labels, hints, validation, defaults and visibility rules.
A field is one input in a form. You create it with make(), passing the name of the attribute it holds, then chain the options you want.
use Xelqun\Forms\Components\TextInput;
TextInput::make('name')
->label('Full name')
->placeholder('Ada Lovelace')
->hint('As it appears on your ID.')
->required();
The options on this page work on every field.
The fields
| Field | Use it for |
|---|---|
| TextInput | Text, email, numbers, passwords and more |
| Textarea | Longer plain text |
| Select | One or many options, from a list or a relationship |
| Checkbox | A single yes or no |
| CheckboxList | Many options, all visible |
| Radio | One option, all visible |
| Toggle | An on and off switch |
| ToggleButtons | Options as a row of buttons |
| DatePicker, TimePicker, DateTimePicker | Dates and times |
| FileUpload | Files and images |
| RichEditor | Formatted text as clean HTML |
| MarkdownEditor | Markdown with a preview |
| CodeEditor | Code, with highlighting |
| ColorPicker | Colors |
| Slider | A number on a track |
| TagsInput | A list of short values |
| KeyValue | Pairs of keys and values |
| Repeater | Rows of fields |
| Builder | Rows of different block types |
| MorphToSelect | A polymorphic relationship |
| Hidden | A value with no control |
Labels and help text
A label comes from the field's name, so first_name reads as "First name". Change it with label().
TextInput::make('email')
->label('Work email')
->placeholder('you@company.com')
->hint('We only use this to sign you in.');
hiddenLabel() hides the label on screen, and screen readers still announce it. inlineLabel() puts it beside the field.
Default values
default() sets the value of a new form. A form filled from a record uses the record's value.
Toggle::make('is_active')->default(true);
Disabling a field
TextInput::make('slug')->disabled();
TextInput::make('slug')->disabledOn('edit');
TextInput::make('reference')->readOnly();
A disabled field isn't submitted. readOnly() shows the value without letting anyone change it, and the server drops whatever the browser sends for it.
Hiding a field
hidden() and visible() take a boolean or a closure. hiddenOn() and visibleOn() take an operation.
TextInput::make('password')->hiddenOn('edit');
TextInput::make('discount')->visible(fn (): bool => auth()->user()->isManager());
To show a field based on another field's value, see conditional logic.
Content around a field
You can place text or components around a field: aboveLabel(), beforeLabel(), afterLabel(), belowLabel(), aboveContent(), beforeContent(), afterContent(), belowContent(), aboveErrorMessage() and belowErrorMessage().
use Xelqun\Forms\Layouts\Text;
TextInput::make('password')
->password()
->belowContent(Text::make('Use at least twelve characters.'));
Buttons beside a field
prefixAction() and suffixAction() place an action right before or after the control.
Fields that aren't saved
saved(false) is for a field with no column. It's still validated, and it's still in validate()'s data. dehydrated(false) leaves the value out of the submitted data altogether.
TextInput::make('terms_accepted')->saved(false);
Changing every field at once
configureUsing() runs on every new instance of a class. Put it in a service provider.
TextInput::configureUsing(function (TextInput $input): void {
$input->trim();
});
Column span
Fields sit in the grid of their parent layout. columnSpan() sets how many columns one takes, and columnSpanFull() gives it the whole row.
TextInput::make('notes')->columnSpanFull();
TextInput::make('city')->columnSpan(['md' => 2, 'xl' => 1]);