Skip to content

File validation message uses instanceof UploadedFile instead of File #49875

@tinyoverflow

Description

@tinyoverflow

Laravel Version

10.34.2

PHP Version

8.2.13

Database Driver & Version

N/A

Description

When using the validator with a manually passed Illuminate\Http\File object, the validation seems to work as expected. The getSize method checks for a Symfony file to determine on how to check that:

} elseif ($value instanceof File) {
return $value->getSize() / 1024;
}

But the returned error message is wrong, as it uses the string message. This seems to be due to the fact that the message formatter does an instanceof Illuminate\Http\UploadedFile:

} elseif ($this->getValue($attribute) instanceof UploadedFile) {
return 'file';
}

I'd expect to both use the same condition to determine on how to validate and on what message to use.

Steps To Reproduce

Example Snippet:

$v = \Illuminate\Support\Facades\Validator::make(
    ['file' => new \Illuminate\Http\File('composer.json')],
    ['file' => 'max:1']
);

dd($v->passes(), $v->messages()->all());

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions