-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Closed
Description
Laravel Version
12.35.0
PHP Version
8.4.7
Database Driver & Version
No response
Description
Since #57356, custom messages for extensions, min, max and size rules are overridden if a file message is also set when using the Illuminate\Validation\Rules\File rule.
We define messages for both file and size rules for a specific uploaded file as part of a form request. If a file is uploaded that is larger than the defined size, the error response is that set for file, not size, i.e. "Not a file".
If no custom file message is set, or if it is set as a catch-all message (e.g. 'file' => '...' vs. 'attachment.file' => '...') the size message takes priority once more.
Steps To Reproduce
use Illuminate\Http\UploadedFile;
use Illuminate\Validation\Rules\File;
use Illuminate\Support\Facades\Validator;
Validator::make(
[
'one' => UploadedFile::fake()->create('file.pdf', 100),
'two' => 'foo',
],
[
'one' => [File::default()->max(50)],
'two' => [File::default()->max(50)],
],
[
'one.max' => 'File is too large',
'one.file' => 'Not a file',
'two.max' => 'File is too large',
'two.file' => 'Not a file',
]
)->errors()->toArray();
// >= 12.35.0
// [
// "one" => ["Not a file"], <- Incorrect message
// "two" => ["Not a file"],
// ]
// <=12.34.0
// [
// "one" => ["File is too large"],
// "two" => ["Not a file"],
// ]Metadata
Metadata
Assignees
Labels
No labels