Using schema and table classes
Since many Filament methods define both the UI and the functionality of the app in just one method, it can be easy to end up with giant methods and files. These can be difficult to read, even if your code has a clean and consistent style. Filament tries to mitigate some of this by providing dedicated schema and table classes when you generate a resource. These classes have aconfigure() method that accepts a $schema or $table. You can then call the configure() method from anywhere you want to define a schema or table.
For example, if you have the following app/Filament/Resources/Customers/Schemas/CustomerForm.php file:
form() method of the resource:
table():
infolist():
configure() method, you would not be able to pass your own configuration variables to the method, which could be useful if you wanted to reuse the same class in multiple places but with slight tweaks.
Using component classes
Even if you are using schema and table classes to keep the schema and table definitions in their own files, you can still end up with a very longconfigure() method. This is especially true if you are using a lot of components in your schema or table, or if the components require a lot of configuration.
You can mitigate this by creating dedicated classes for each component. For example, if you have a TextInput component that requires a lot of configuration, you can create a dedicated class for it:
- Schema components: These could live in the
Schemas/Componentsdirectory of the resource. They could be named after the component they are wrapping, for exampleCustomerNameInputorCustomerCountrySelect. - Table columns: These could live in the
Tables/Columnsdirectory of the resource. They could be named after the column followed byColumn, for exampleCustomerNameColumnorCustomerCountryColumn. - Table filters: These could live in the
Tables/Filtersdirectory of the resource. They could be named after the filter followed byFilter, for exampleCustomerCountryFilterorCustomerStatusFilter. - Actions: These could live in the
Actionsdirectory of the resource. They could be named after the action followed byActionorBulkAction, for exampleEmailCustomerActionorUpdateCustomerCountryBulkAction.
EmailCustomerAction class:
getHeaderActions() of a page: