onramplab/laravel-custom-fields
Product, User, Event), reducing redundancy. This fits well in systems with shared metadata needs (e.g., e-commerce, SaaS platforms).custom_fields), isolating them from core model tables. This preserves database integrity while enabling extensibility.custom_field_values) may introduce query complexity or performance bottlenecks if not optimized (e.g., N+1 queries for bulk fetches).$model->custom_fields), blending with existing Laravel patterns (e.g., hasManyThrough relationships).required, max) and JSON serialization, easing API integration.remember()) or lazy-loading.CustomFieldable trait for easy adoption.custom_fields collection.GET /products/{id} → { ...custom_fields: [...] }).createCustomField() helpers). Supports feature tests for custom field logic.json columns with structured custom fields).composer require, php artisan vendor:publish).php artisan migrate) to create custom_fields and custom_field_values tables.CustomFieldable trait and define field groups (e.g., product_attributes).is_custom_field flag or archive old columns post-migration.pdo_mysql).created_at fields).Product) to validate the approach.with('customFields')).CustomFieldUpdated).custom_fields table or migrate to a dedicated field_definitions table for complex setups.custom_fields for X, not for Y").User uses 500 custom fields").price must be numeric").with() or load().| Issue Type | Resolution Path |
|---|---|
| Query Performance | Optimize indexes, cache results |
| Field Validation | Extend Laravel’s validation rules |
| Migration Failures | Rollback and retry with batch processing |
custom_field_values.model_type and custom_field_values.model_id for polymorphic queries.custom_field_values by model_type or created_at.Cache::remember("model:{$id}:custom_fields", ...)).Cache::tags(['custom_fields'])->flush() on field updates).CustomFieldUpdated event dispatched to custom-fields queue).| Failure Scenario | Impact | Mitigation Strategy |
|---|---|---|
| Database connection loss | Custom field data unavailability | Retry logic with exponential backoff |
| Polymorphic join table corruption | Data loss/inconsistency | Regular backups, transactional writes |
| Field type serialization errors | Invalid data in storage | Input validation, type casting |
| Cache stampede | Performance degradation | Distributed cache (Redis), cache warming |
| Unbounded custom field growth | Storage bloat | Set soft limits (e.g., "Max 100 fields/model") |
How can I help you explore Laravel packages today?