Preset Custom Fields allow developers to programmatically define, deploy, and manage custom fields for Filament resources using migrations.
This approach ensures consistency, version control, and easy deployment across different environments.
To create a new custom fields migration, use the dedicated Artisan command:
This command generates a new migration file in your database/migrations/custom-fields
directory with a timestamp prefix and the name you specified.
The CustomFieldType
enum provides various field types you can use. Here are some common types and their associated properties:
TEXT
: Basic text input
NUMBER
: Numeric input
SELECT
: Dropdown selection
MULTI_SELECT
: Multiple selection
DATE
: Date picker
TOGGLE
: Boolean toggle switch
TEXTAREA
: Multi-line text input
Refer to the CustomFieldType
enum for a complete list of available field types.
In your migration file, use the new()
method to create new custom fields:
To update existing fields, create a new migration and use the update()
method:
To remove preset fields, create a migration that uses the delete()
method:
Note: Deleting a field with function forceDelete is permanent and will result in data loss. Ensure you have backups and that no part of your application depends on the field being deleted.
To restore preset fields, create a migration that uses the restore()
method:
To deploy your preset custom fields, run the standard Laravel migration command:
Naming Conventions: Use clear, descriptive names for your migration files.
Versioning: Create separate migrations for creating, updating, and deleting fields to maintain a clear history.
Idempotency: Ensure your migrations are idempotent (can be run multiple times without side effects).
Documentation: Comment your migrations to explain the purpose of each change.
Data Integrity: When updating or deleting fields, consider the impact on existing data.