Product Decisions This Supports
- Flexible Data Models: Enables rapid iteration on schema without migrations, reducing devops overhead for non-critical attributes (e.g., user profiles, product variants, or event metadata).
- Build vs. Buy: Avoids reinventing polymorphic custom-field logic while maintaining control over field definitions (vs. SaaS solutions like Airtable or custom-built solutions).
- Roadmap Priorities:
- MVP Acceleration: Launch features faster by deferring database changes (e.g., A/B testing variants, user-submitted content).
- Admin Panels: Power dynamic forms for CMS-like functionality (e.g., "Add any metadata to your blog posts").
- Extensibility: Future-proof for third-party integrations (e.g., syncing custom fields to external APIs).
- Use Cases:
- Content Management: Dynamic metadata for blog posts, products, or events.
- User Profiles: Optional fields without schema migrations (e.g., "Favorite Color").
- E-Commerce: Variant-specific attributes (e.g., "Material" for clothing items).
- Internal Tools: Configurable dashboards or workflows (e.g., "Project Tags").
When to Consider This Package
-
Adopt When:
- Your team needs dynamic attributes but lacks time/resources for schema migrations.
- You’re using Laravel 8+ and PHP 8+ (no polyfill overhead).
- Custom fields are non-core (e.g., not used in critical queries or reports).
- You prioritize developer velocity over strict data integrity (e.g., no need for database constraints).
- Your use case aligns with supported field types (no complex nested structures or file uploads).
-
Look Elsewhere If:
- You need complex validation or business-critical data (consider Eloquent relationships or dedicated tables).
- Your team requires fine-grained access control (e.g., field-level permissions) out of the box.
- You’re using Laravel <8 or need multi-tenancy isolation for custom fields.
- Field data must be indexed/searchable (this package relies on JSON columns or similar).
- You need versioning or audit logs for custom fields (requires custom implementation).
- Your use case involves large-scale data (performance may degrade with thousands of fields per model).
How to Pitch It (Stakeholders)
For Executives:
"This package lets us add flexible, non-critical data fields to any model—like letting users customize their profiles or products—without slowing down development or requiring database changes. Think of it as ‘sticky notes’ for your database: quick to add, easy to manage, and no migration headaches. Ideal for MVPs, admin panels, or dynamic content where rigidity isn’t a priority. Low risk (MIT license, active maintenance), high reward for speed."
For Engineering:
*"Laravel-custom-fields gives us a battle-tested way to add polymorphic, dynamic attributes to models without schema changes. Key benefits:
- No migrations: Add fields via code/config (e.g.,
CustomField::defineFor(User::class, ['bio', 'preferred_language'])).
- Type safety: Supports strings, numbers, booleans, selects, and datetimes with validation.
- Polymorphic: Works across any model (e.g.,
Post, Product, User).
- Lightweight: ~500 LOC, no bloat—just what we need for flexibility.
Tradeoff: Not for high-performance or complex queries, but perfect for admin panels, user-generated metadata, or experimental features. Example use case: Let’s use this for our ‘Event’ model’s dynamic attributes instead of adding columns every time a client asks for ‘new fields.’"*
For Developers:
*"This package abstracts away the boilerplate for dynamic fields. Here’s how you’d use it:
- Define fields:
CustomField::defineFor(Product::class, [
'material' => ['type' => 'select', 'options' => ['cotton', 'polyester']],
'weight_kg' => ['type' => 'float'],
]);
- Access fields:
$product = Product::find(1);
$product->custom_fields->material; // 'cotton'
- Update dynamically:
$product->custom_fields->add('release_year', ['type' => 'integer']);
- Pros: No DB changes, supports validation, and works with Eloquent.
- Cons: Fields are stored as JSON (querying requires
->whereJsonContains()), and no built-in UI—you’ll need a form package like Livewire or Nova for admin tools.
Best for: Quick prototypes, admin panels, or any case where you’d otherwise reach for a data JSON column."*