getName()}"); } /** * The input fields. * * @return InputField[] */ public function fields(): array { $fields = []; $baseType = $this->type; $fields[] = collect($baseType->fieldClasses()) ->filter(fn (Field $field) => $field instanceof CreatableField) // and reportable field? ->map( fn (Field&CreatableField $field) => new InputField($field->getName(), $field->type().($field instanceof RequiredOnCreation ? '!' : '')) ) ->toArray(); $fields[] = collect($baseType->relations()) ->mapWithKeys(function (Relation $relation) { $baseType = $relation->getBaseType(); if (! $baseType instanceof EloquentType) { return []; } return match (true) { $relation instanceof BelongsToRelation => [$relation->getName() => new CreateBelongsToInput($baseType)], $relation instanceof HasManyRelation => [$relation->getName() => new CreateHasManyInput($baseType)], $relation instanceof BelongsToManyRelation => [$relation->getName() => new CreateBelongsToManyInput($relation->getEdgeType()->getPivotType())], default => [], }; }) ->map(fn (Input $input, string $name) => new InputField($name, $input->getName())) ->toArray(); return Arr::flatten($fields); } }