filamentphp/filament · error · InvalidArgumentException
Field of class [$fieldClass] must have a unique name, passed
Error message
Field of class [$fieldClass] must have a unique name, passed to the [make()] method.
What it means
Every form Field's name doubles as its state path and the array key it is saved under, so a null name is always a bug. `Field::make()` falls back to `getDefaultName()` (null in the base class) and throws an InvalidArgumentException when the result is still `null` — note the check is `=== null`, so an empty string is not caught here and fails later instead.
Source
Thrown at packages/forms/src/Components/Field.php:80
const ABOVE_ERROR_MESSAGE_SCHEMA_KEY = 'above_error_message';
const BELOW_ERROR_MESSAGE_SCHEMA_KEY = 'below_error_message';
final public function __construct(string $name)
{
$this->name($name);
$this->statePath($name);
}
public static function make(?string $name = null): static
{
$fieldClass = static::class;
$name ??= static::getDefaultName();
if ($name === null) {
throw new InvalidArgumentException("Field of class [$fieldClass] must have a unique name, passed to the [make()] method.");
}
$static = app($fieldClass, ['name' => $name]);
$static->configure();
return $static;
}
protected function setUp(): void
{
parent::setUp();
$this->setUpHint();
}
public static function getDefaultName(): ?string
{View on GitHub (pinned to 53483fa934)
Solutions
- Pass an explicit name: `TextInput::make('title')`.
- Default dynamic values: `TextInput::make($column ?? $fallback)`.
- In custom field classes, override `getDefaultName()` to return a stable identifier.
Example fix
// before
TextInput::make($column) // $column is null
->required(),
// after
TextInput::make($column ?? 'title')
->required(), Defensive patterns
Strategy: type-guard
Validate before calling
foreach ($columns as $key => $meta) {
if ($key === null) {
continue; // or collect for a config error report
}
$fields[] = TextInput::make($key);
} Type guard
function assertFieldName(?string $name): string
{
if ($name === null) {
throw new InvalidArgumentException('Field name cannot be null.');
}
return $name;
}
// TextInput::make(assertFieldName($column)) Prevention
- Default dynamic names instead of passing possibly-null variables.
- Validate schema-generating config (DB metadata, YAML) for null keys before building fields.
- Note the base check is === null: an empty string slips through and misbehaves later, so guard blanks too.
When it happens
Trigger: `TextInput::make()` with no argument, or `TextInput::make($columnName)` where `$columnName` evaluates to null (missing array key, null config value) at schema construction time.
Common situations: Generating fields from database metadata or config maps where a key is absent, destructuring with a wrong variable, or copy-paste where the name got deleted.
Related errors
- Import column of class [$importColumnClass] must have a uniq
- Block of class [$blockClass] must have a unique name, passed
- MorphToSelect of class [$morphToSelectClass] must have a uni
- The relationship [{$name}] does not exist on the model [{$th
- You cannot use the `disableToolbarButtons()` method when the
AI-assisted analysis of filamentphp/filament@53483fa934 (2026-08-17).
Data as JSON: /api/errors/ab505aac896638bd.
Report an issue: GitHub.