Creating Custom Fields Migrations
To create a new custom fields migration, use the dedicated Artisan command:database/migrations/custom-fields
directory with a timestamp prefix and the name you specified.
Field Types and Properties
TheCustomFieldType
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
CustomFieldType
enum for a complete list of available field types.
Creating Fields
In your migration file, use thenew()
method to create new custom fields:
Updating Fields
To update existing fields, create a new migration and use theupdate()
method:
Deleting Fields
To remove preset fields, create a migration that uses thedelete()
method:
Restoring Fields
To restore preset fields, create a migration that uses therestore()
method:
Deploying Preset Fields
To deploy your preset custom fields, run the standard Laravel migration command:Best Practices
- 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.