Demonstrates how to use dynamic custom fields in Filament Forms, similar to WordPress.
The main logic here lives in our CustomerResource
classes form()
method:
Repeater
to create a dynamic number of fieldsPivot
model to enable our Many-to-Many relationship between Customer
and Field
modelsHere's how that looks in our code:
app/Models/Field.php
class Field extends Model{ protected $fillable = [ 'name', ];}
app/Models/CustomerField.php
use Illuminate\Database\Eloquent\Relations\BelongsTo;use Illuminate\Database\Eloquent\Relations\Pivot; class CustomerField extends Pivot{ public function customer(): BelongsTo { return $this->belongsTo(Customer::class); } public function field(): BelongsTo { return $this->belongsTo(Field::class); }}
Remember that this Model is required for the Repeater
to work, as it's a Many-to-Many relationship. That's a Filament requirement.