Skip to main content

Schema-Based Forms

In Filament v4, forms are defined using the Schema class rather than a dedicated Form class. This provides a unified approach for forms, infolists, and other component layouts.

Basic Usage

use Filament\Schemas\Schema;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Select;

public static function form(Schema $schema): Schema
{
    return $schema
        ->components([
            TextInput::make('name')
                ->required(),
            Select::make('status')
                ->options([
                    'draft' => 'Draft',
                    'published' => 'Published',
                ]),
        ]);
}

Schema Class

The Schema class is the foundation for building form layouts in Filament v4.

Namespace

Filament\Schemas\Schema

Methods

components()

Define the components in the schema.
public function components(array $components): static
components
array
An array of form field components.
return
static
Returns the schema instance for method chaining.
Example:
$schema->components([
    TextInput::make('email')->email(),
    TextInput::make('password')->password(),
]);

operation()

Set the operation context for the schema.
public function operation(string $operation): static
operation
string
The operation name (e.g., ‘create’, ‘edit’, ‘view’).
return
static
Returns the schema instance for method chaining.

statePath()

Set the state path for the schema.
public function statePath(?string $path): static
path
string | null
The state path for data binding.
return
static
Returns the schema instance for method chaining.

columns()

Set the number of columns for the schema layout.
public function columns(int | array $columns): static
columns
int | array
Number of columns or responsive column configuration.
return
static
Returns the schema instance for method chaining.
Example:
$schema->columns([
    'sm' => 1,
    'md' => 2,
    'lg' => 3,
]);

Form Context

Forms in Filament operate within different contexts:

Operations

  • create - Creating a new record
  • edit - Editing an existing record
  • view - Viewing a record (read-only)
Example:
use Filament\Forms\Components\TextInput;

TextInput::make('name')
    ->disabled(fn (string $operation): bool => $operation === 'view');

Form Fields

All form fields extend the Field base class. See the Field API reference for details.

Common Form Components

  • TextInput - Text input field
  • Textarea - Multi-line text area
  • Select - Dropdown select
  • Checkbox - Single checkbox
  • Toggle - Toggle switch
  • Radio - Radio button group
  • DatePicker - Date picker
  • DateTimePicker - Date and time picker
  • FileUpload - File upload
  • RichEditor - Rich text editor
  • MarkdownEditor - Markdown editor
  • ColorPicker - Color picker
  • KeyValue - Key-value pair input
  • Repeater - Repeatable field groups
  • Builder - Flexible content builder

Layout Components

  • Section - Collapsible section
  • Fieldset - Fieldset grouping
  • Grid - Grid layout
  • Tabs - Tabbed interface
  • Wizard - Multi-step wizard
  • Group - Component grouping

Data Binding

Forms automatically bind to Livewire properties using the state path. Example:
// In a resource
public static function form(Schema $schema): Schema
{
    return $schema
        ->statePath('data')
        ->components([
            TextInput::make('name'),
        ]);
}

// Data is bound to $this->data['name']

Validation

Validation rules are defined on field components. Example:
use Filament\Forms\Components\TextInput;

TextInput::make('email')
    ->required()
    ->email()
    ->maxLength(255);

Form State

Access and modify form state using closures: Example:
use Filament\Forms\Components\TextInput;
use Filament\Forms\Get;
use Filament\Forms\Set;

TextInput::make('price')
    ->numeric()
    ->live()
    ->afterStateUpdated(function (Set $set, ?float $state) {
        $set('total', $state * 1.2);
    });

TextInput::make('total')
    ->disabled();

Build docs developers (and LLMs) love