Introduction
Schemas form the foundation of Filament’s Server-Driven UI approach. They allow you to build user interfaces declaratively using PHP configuration objects. These configuration objects represent components that define the structure and behavior of your UI, such as forms, tables, or lists. Rather than manually writing HTML or JavaScript, you create these schemas to control what gets rendered on the server, streamlining development and ensuring consistency across your app. Schemas are used extensively across Filament to render UI elements dynamically. Whether you’re defining a form field, the layout of your page, or an action button, the schema object defines both the component’s configuration and how it interacts with your data. In essence, schemas are the building blocks of Filament UIs. Filament packages provide you with various components. You can find a full list in the available components section:- Form fields accept input from the user, for example, a text input, a select, or a checkbox. They come with integrated validation.
- Infolist entries are components for rendering “description lists.” Entries are key-value UI elements that can present read-only information like text, icons, and images. The data for an infolist can be sourced from anywhere but commonly comes from an individual Eloquent record.
- Layout components are used to structure the components. For example, a grid, tabs, or a multi-step form wizard.
- Prime components are simple components that are used to render basic stand-alone static content, such as text, images, and buttons (actions).
Filament\Schemas\Schema object, and you can pass an array of components to it in the components() method.
Available components
For building forms, Filament includes a set of fields for different data types:- Text input
- Select
- Checkbox
- Toggle
- Checkbox list
- Radio
- Date-time picker
- File upload
- Rich editor
- Markdown editor
- Repeater
- Builder
- Tags input
- Textarea
- Key-value
- Color picker
- Toggle buttons
- Slider
- Code editor
- Hidden
- Or, build your own custom form field
- Text entry
- Icon entry
- Image entry
- Color entry
- Code entry
- Key-value entry
- Repeatable entry
- Or, build your own custom infolist entry
- Grid
- Flex
- Fieldset
- Section
- Tabs
- Wizard
- Callout
- Empty states
- Or, build your own custom layout component
An example schema
For example, you may want to build a form with a schema. The name of the schema is usually dictated by the name of the method that it is defined in (form in this example). Filament creates the Schema object and passes it to the method, which then returns the schema with the components added:
make() method. The schema() method is used to nest components within the grid.
Section is another layout component that renders multiple components together in a card, with a heading at the top.
TextInput, Select, and Checkbox are form components that accept input from the user.
TextEntry is an infolist component that displays read-only information. In this example, it is used to display the created and updated timestamps of the record. The dateTime() method is used to format the timestamps as dates and times.
The schema object is the container for the components and can now be rendered. Rendering the schema will render all the components within it in the correct layout.
Component utility injection
The vast majority of methods used to configure entries accept functions as parameters instead of hardcoded values:Injecting the state of another component
You may also retrieve the state (value) of a form field or infolist entry from within a callback, using a$get parameter:
Injecting the current Eloquent record
You may retrieve the Eloquent record for the current schema using a$record parameter:
Injecting the current operation
If you’re writing a schema for a panel resource or relation manager, and you wish to check if a schema iscreate, edit or view, use the $operation parameter:
You can manually set a schema’s operation using the
$schema->operation() method.Injecting the current Livewire component instance
If you wish to access the current Livewire component instance, define a$livewire parameter:
Injecting the current component instance
If you wish to access the current component instance, define a$component parameter:
Injecting multiple utilities
The parameters are injected dynamically using reflection, so you are able to combine multiple parameters in any order:Injecting dependencies from Laravel’s container
You may inject anything from Laravel’s container like normal, alongside utilities:Global settings
If you wish to change the default behavior of a component globally, then you can call the staticconfigureUsing() method inside a service provider’s boot() method, to which you pass a Closure to modify the component using. For example, if you wish to make all section components have 2 columns by default, you can do it like so: