{"record":{"id":"bc9f68f64cd9cbeb","repo":"filamentphp/filament","slug":"morphtoselect-of-class-morphtoselectclass-must","errorCode":null,"errorMessage":"MorphToSelect of class [$morphToSelectClass] must have a unique name, passed to the [make()] method.","messagePattern":"MorphToSelect of class \\[\\$morphToSelectClass\\] must have a unique name, passed to the \\[make\\(\\)\\] method\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"packages/forms/src/Components/MorphToSelect.php","lineNumber":61,"sourceCode":"    protected ?Closure $modifyTypeSelectUsing = null;\n\n    protected ?Closure $modifyKeySelectUsing = null;\n\n    protected bool | Closure $hasTypeSelectToggleButtons = false;\n\n    final public function __construct(string $name)\n    {\n        $this->name($name);\n    }\n\n    public static function make(?string $name = null): static\n    {\n        $morphToSelectClass = static::class;\n\n        $name ??= static::getDefaultName();\n\n        if (blank($name)) {\n            throw new InvalidArgumentException(\"MorphToSelect of class [$morphToSelectClass] must have a unique name, passed to the [make()] method.\");\n        }\n\n        $static = app($morphToSelectClass, ['name' => $name]);\n        $static->configure();\n\n        return $static;\n    }\n\n    protected function setUp(): void\n    {\n        parent::setUp();\n\n        $this->schema(function (MorphToSelect $component): array {\n            $relationship = $component->getRelationship();\n            $typeColumn = $relationship->getMorphType();\n            $keyColumn = $relationship->getForeignKeyName();\n\n            $types = $component->getTypes();","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/filamentphp/filament/blob/53483fa9340e4ec637985fe454ebb58afb92ea24/packages/forms/src/Components/MorphToSelect.php#L43-L79","documentation":"MorphToSelect's name is also the state path and the key under which the morph type/id pair is stored, so it must be unique and non-blank. `make()` falls back to `getDefaultName()` (null on the base class) and throws an InvalidArgumentException when the name is still blank after the fallback.","triggerScenarios":"`MorphToSelect::make()` with no argument, or `MorphToSelect::make($name)` where `$name` is null/empty when the form schema is built.","commonSituations":"Custom morph-select subclasses without a `getDefaultName()` override, or schema generation from metadata where the key is missing.","solutions":["Pass an explicit name matching the morph relation: `MorphToSelect::make('commentable')`.","Override `getDefaultName()` in custom subclasses to return a stable identifier.","Guard dynamic schema builders against null names."],"exampleFix":"// before\nMorphToSelect::make()\n    ->types([...]),\n\n// after\nMorphToSelect::make('commentable')\n    ->types([...]),","handlingStrategy":"type-guard","validationCode":"foreach ($morphFields as $name => $definition) {\n    if (blank($name)) {\n        continue;\n    }\n\n    $fields[] = MorphToSelect::make($name)->types($definition['types']);\n}","typeGuard":"function assertMorphToSelectName(?string $name): string\n{\n    if (blank($name)) {\n        throw new InvalidArgumentException('MorphToSelect name cannot be blank.');\n    }\n\n    return $name;\n}\n\n// MorphToSelect::make(assertMorphToSelectName($name))","tryCatchPattern":null,"preventionTips":["Always name MorphToSelect after the morphTo() relation method.","Validate schema-generating config arrays for blank keys.","Override getDefaultName() in custom subclasses that have a fixed purpose."],"tags":["filament","forms","morph-to-select","schema","component-name"],"backgroundTag":"missing-component-name","analyzedSha":"53483fa9340e4ec637985fe454ebb58afb92ea24","analyzedAt":"2026-08-17T02:06:23.049Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}