Form with Custom Fields

Filament 4
Also available in Filament 3 version

Demonstrates how to use dynamic custom fields in Filament Forms, similar to WordPress.

ZyfHwB6lJYj3H3WB41vphJmuzzxzs5-metaMjItZm9ybS1jdXN0b20tZmllbGRzLnBuZw==-

Get the Source Code:

How it works

The main logic here lives in our CustomerResource classes form() method:

  • We are using a Repeater to create a dynamic number of fields
  • We are using a Pivot model to enable our Many-to-Many relationship between Customer and Field models
  • We are turning off fields as soon as they are selected to prevent duplicates

Here'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.

The FULL tutorial is available after the purchase: in the Readme file of the official repository you would get invited to.
Get the Source Code: All 152 Premium Examples for $99