Quickstart
This section will guide you through setting up and using the Custom Fields plugin in your Filament admin panel.
Publish and Run Migrations
Publish the migration files:
Run the migrations:
Publish the Configuration File (Optional)
If you wish to customize the configuration, publish the config file:
This will create a custom-fields.php
file in your config
directory.
Integrating Custom Fields Plugin into panel
To use Custom Fields, you need to register the plugin with your Filament panel.
Setting Up the Model
Your model needs to implement the HasCustomFields
interface and use the UsesCustomFields
trait to work with custom
fields.
In your model (e.g., Company
), add the following:
By following these steps, your model will be fully equipped to handle custom fields, and you will have successfully set up Custom Fields in your Filament application, enabling dynamic and flexible data management.
Adding Custom Fields to Forms
To include custom fields in your resource forms, you’ll use the CustomFieldsComponent
. This component dynamically adds
all the custom fields associated with the resource.
In your resource class (e.g., CompanyResource
), modify the form()
method:
Displaying Custom Fields in Table Views
To display custom fields in your table views, you need to use the InteractsWithCustomFields
trait in your
resource’s ListRecords
page.
In your list records class (e.g., ListCompanies
), add the trait:
This trait automatically includes all custom fields in the table view for the resource.
Integrating into Info Lists
In your resource’s ViewRecord
page or wherever you define the info list schema, include the CustomFieldsInfolists
component:
Including Custom Fields in Exports
To include custom fields in your exports, you can leverage the CustomFieldsExporter
component, which is designed to integrate seamlessly with Filament’s exporting tools. Below is your CompanyExporter
class, which shows how to implement this: