CustomerResource:
Please note: when building forms for resources, please ensure that you are using components within theFilament\Resources\Forms\Componentsnamespace and notFilament\Forms\Components.
Fields
Resource field classes are located in theFilament\Resources\Forms\Components namespace.
All field components have access to the following customization methods:
Checkbox
Date Picker
Date-time Picker
File Upload
Please note, it is the responsibility of the developer to delete these files from the disk if they are removed, as Filament is unaware if they are depended on elsewhere. One way to do this automatically is observing a model event.
To customize Livewire’s default file upload validation rules, please refer to its documentation.
Available values for the position methods can be found on Filepond’s website.
Support for multiple file uploads is coming soon.
Key-value
Markdown Editor
Toolbar Buttons
Rich Editor
Toolbar Buttons
Select
If you’re looking to use a select for abelongsTo()relationship, please check out theBelongsToSelectresource field.
Tags Input
Textarea
Text Input
Toggle
TheonIcon() and offIcon() methods support the name of any Blade icon component, and passes a set of formatting classes to it. By default, the Blade Heroicons package is installed, so you may use the name of any Heroicon out of the box. However, you may create your own custom icon components or install an alternative library if you wish.
Validation
Filament provides a number of validation methods that can be applied to fields. Please refer to the Laravel Validation docs if you are unsure about any of these.rules() method:
Please note: when specifying resource field names in custom validation rules, you must prefix them with record..
Layout
Grid
By default, form fields are stacked on top of each other in one column. To change this across the entire form, you may chain thecolumns() method onto the form object:
Section
You may want to separate your fields into sections, each with a heading and subheading. To do this, you can use a Section component:schema() method to declare the section schema late:
columns() method to easily create a grid within the section:
collapsible() to optionally hide content in long forms:
collapse() sections by default:
Fieldset
You may want to group fields into a Fieldset. Each fieldset has a label, a border, and a two-column grid:columns() method to customize the number of columns in the fieldset:
Tabs
Some forms can be long and complex. You may want to use tabs to reduce the number that are available at once:columns() method to easily create a grid within the tab:
Group
Groups are used to wrap multiple associated form components. They have no effect on the form visually, but are useful for applying modifications to many fields at once:Placeholder
Placeholders can be used to render text-only “fields” within your forms. Each placeholder has a value, which is cannot be changed by the user.Dependent Fields
Dependent fields are fields that are modified based on the value of another. For example, you could show a group of fields based on the value of a Select. The first step to setting up dependent fields is to apply thedependable() method to the field that should be watched for changes. When the value of this field is changed, the whole form will reload:
when() method. The first argument to this method is a callback that evaluates the $record object, and returns true or false depending on if the modifications should be applied. The second argument makes modifications to the current field. If no second argument is supplied, the field will only be shown when the callback in the first argument is true:
In this example, the fields in the group will only be shown when the type field is set to individual:
company_number field will only be required when the type field is set to organization:
Context Customization
You may customize forms based on the page they are used. To do this, you can chain theonly() or except() methods onto any form component.
name field will only() be displayed on the CreateCustomer page.
name field will be required, except() on the EditCustomer page.
This is an incredibly powerful pattern, and allows you to completely customize a form contextually by chaining as many methods as you wish to the callback.
Developing Custom Components
To create a custom field, you may use:View component, and passing the name of a $view in your app: