feat: add FieldDataType::FILE to fix file upload validation#100
feat: add FieldDataType::FILE to fix file upload validation#100ManukMinasyan merged 1 commit into3.xfrom
Conversation
File upload fields stored paths in string_value, causing DatabaseFieldConstraints to add max:255 (characters) which Laravel interpreted as 255 KB when combined with the 'file' rule. Adds FieldDataType::FILE with FieldSchema::file() factory method. FILE maps to string_value for storage but skips database column constraints, since validation runs against the uploaded file, not the stored path.
There was a problem hiding this comment.
Pull request overview
Adds a first-class FieldDataType::FILE to ensure file upload custom fields validate the uploaded file correctly without inheriting string_value (VARCHAR 255) column constraints that conflict with Laravel’s file rule semantics.
Changes:
- Introduces
FieldDataType::FILEplusFieldSchema::file()and updatesFileUploadFieldTypeto use it. - Maps
FILEtostring_valuestorage while updating validation logic to skip DB column constraints for file data types. - Adds integration tests covering column resolution and validation rule composition for file uploads.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
tests/Feature/Integration/FileUploadValidationTest.php |
New tests asserting FILE storage mapping and that DB constraints are skipped for file uploads. |
src/Services/ValidationService.php |
Skips DB constraint merging for FieldDataType::FILE to avoid max:255 being treated as KB. |
src/Models/CustomFieldValue.php |
Maps FieldDataType::FILE to string_value. |
src/FieldTypeSystem/FieldSchema.php |
Adds FieldSchema::file() factory. |
src/FieldTypeSystem/Definitions/FileUploadFieldType.php |
Uses FieldSchema::file() for the file upload field type. |
src/Enums/FieldDataType.php |
Adds FILE enum case and compatible visibility operators. |
src/Console/Commands/MakeFieldTypeCommand.php |
Adds scaffolding support for FILE (configurator + Filament FileUpload component generation). |
Comments suppressed due to low confidence (1)
src/Services/ValidationService.php:120
getDatabaseValidationRules()callsCustomFieldsType::getFieldType()to detectFieldDataType::FILE, and then (for non-FILE types) callsCustomFieldValue::getValueColumn($fieldType), which internally callsCustomFieldsType::getFieldType()again. BecauseFieldManager::getFieldType()rebuilds the field type collection (instantiating all field type definitions) on each call, this introduces redundant work on a hot path. Consider retrieving theFieldTypeDataonce and deriving the value column from itsdataType, or adding an overload/helper that acceptsFieldTypeData/FieldDataTypeto avoid repeated lookups.
// File types validate the uploaded file, not the stored path
$fieldTypeData = CustomFieldsType::getFieldType($fieldType);
if ($fieldTypeData?->dataType === FieldDataType::FILE) {
return [];
}
// Determine the database column for this field type
$columnName = CustomFieldValue::getValueColumn($fieldType);
// Get base database rules for this column
$dbRules = DatabaseFieldConstraints::getValidationRulesForColumn($columnName, $isEncrypted);
| // File types validate the uploaded file, not the stored path — skip DB constraints | ||
| $fieldTypeData = CustomFieldsType::getFieldType($fieldType); | ||
|
|
||
| if ($fieldTypeData?->dataType === FieldDataType::FILE) { | ||
| return $mergedRules; | ||
| } |
There was a problem hiding this comment.
mergeAllValidationRules() performs another CustomFieldsType::getFieldType($fieldType) lookup to decide whether to skip DB constraints for files. This duplicates the lookup already done earlier in getDatabaseValidationRules() and can be avoided by passing the resolved FieldDataType (or a skipDbConstraints boolean) into this method, reducing repeated field-type resolution work.
| protected function getConfiguratorForDataType(FieldDataType $dataType): string | ||
| { | ||
| return match ($dataType) { | ||
| FieldDataType::STRING => 'text()', | ||
| FieldDataType::TEXT => 'text()', | ||
| FieldDataType::NUMERIC => 'numeric()', | ||
| FieldDataType::FLOAT => 'float()', | ||
| FieldDataType::DATE => 'date()', | ||
| FieldDataType::DATE_TIME => 'dateTime()', | ||
| FieldDataType::BOOLEAN => 'boolean()', | ||
| FieldDataType::SINGLE_CHOICE => 'singleChoice()', | ||
| FieldDataType::MULTI_CHOICE => 'multiChoice()', | ||
| FieldDataType::FILE => 'file()', | ||
| }; |
There was a problem hiding this comment.
getConfiguratorForDataType() (and related methods) now support FieldDataType::FILE, but getDataType()'s interactive $options list doesn’t include a file entry. This makes the new data type unreachable when running the command without --type=file. Add a file option to the prompt/choice list so the scaffolder can generate FILE field types via the interactive flow as well.
Summary
FieldDataType::FILEenum case withFieldSchema::file()factory methodstring_valuefor storage but skips database column constraints in validationstring_valuecolumn'smax:255being interpreted as kilobytes when combined with thefilevalidation ruleProblem
File upload custom fields use
FieldSchema::string()which stores file paths instring_value(VARCHAR 255).DatabaseFieldConstraintsaddsstring+max:255rules for that column. When combined with thefiledefault validation rule, Laravel interpretsmax:255as 255 KB file size limit instead of 255 characters — causing valid file uploads (e.g., a 608 KB PDF) to fail validation.Solution
Introduces
FieldDataType::FILEas a first-class data type that:string_valuefor storage (file paths fit in VARCHAR 255)FieldSchema::file()factory for semantic clarityFileUploadFieldTypeto useFieldSchema::file()instead ofFieldSchema::string()Files changed
FieldDataTypeFILE = 'file'case with visibility operatorsFieldSchemafile()factory methodFileUploadFieldTypeFieldSchema::file()CustomFieldValueFILEtostring_valueValidationServiceFILEdata typeMakeFieldTypeCommandFILEin scaffoldingTest plan
FileUploadValidationTestwith 5 tests covering:string_valuecolumnstringormax:255rules applied to file uploadsmax_size_kbworks correctlygetDatabaseValidationRulesreturns empty for file typesFieldDataType::FILEenum behavior