我目前正在以一种形式工作。
我在多个文件上传验证方面遇到一些问题。我的表单中只有一个字段允许上传多个文件。
<input type="file" name="file[]" multiple="multiple">
这是我的验证,
$this->validate($request, [
'file' =>'required',
'file.*' => 'required|mimes:pdf,jpeg,png |max:4096',
],
$messages = [
'mimes' => 'Only PDF, JPEG, PNG are allowed.'
]
);
验证工作正常,但我无法在刀片文件中显示错误消息。
这是我的尝试。
@if($errors->has('file'))
<span class="help-block">
<strong>{{$errors->first('file')}}</strong>
</span>
@endif
这是为了在没有上传文件时显示错误。
假设我上传了以下文件,
abc.jpg
abc.html
abc.pdf
当 mimes 类型验证抛出错误时,我无法显示错误消息。
在这种情况下,错误被抛出为$error->first(file.1)
因为验证在索引 1 处失败
该索引可以是根据上传的文件的任意索引$error->first(file.*)
效果不太好。
当我仅从表单添加无效文件后显示所有错误时,我遇到了这些错误。
Only PDF, JPEG, PNG are allowed.
The type field is required.
The number field is required.
The expiry date field is required.
任何人对此都有想法。任何帮助表示赞赏。
Thanks,