Php Laravel多文件上传验证

Php Laravel多文件上传验证,php,laravel,validation,file-upload,Php,Laravel,Validation,File Upload,我目前在一家公司工作 我对多文件上传验证有一些问题。我在表单中只有一个字段,允许多个文件上传 <input type="file" name="file[]" multiple="multiple"> 验证工作正常,但我无法在blade文件中显示错误消息 以下是我的尝试 @if($errors->has('file')) <span class="help-block"> <strong>{{$errors->first(

我目前在一家公司工作

我对多文件上传验证有一些问题。我在表单中只有一个字段,允许多个文件上传

<input type="file" name="file[]" multiple="multiple">
验证工作正常,但我无法在blade文件中显示错误消息

以下是我的尝试

@if($errors->has('file'))
    <span class="help-block">
        <strong>{{$errors->first('file')}}</strong>
    </span>
@endif
当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. 
任何人都知道这件事。感谢您的帮助


谢谢,

您可以使用check查看图像

$errors->has('file.*')

尝试这样来验证

'file.*.mimes' => 'Only PDF, JPEG, PNG are allowed.',

这不是个好办法,但对我的情况来说没问题

我有验证规则

'file' =>'required',
'file.*' => 'required|mimes:pdf,jpeg,png |max:4096',
以及,错误消息

'file.*' => 'Only PDF, JPEG, PNG are allowed.'
因为我只有一个文件上传字段,所以我刚刚在所有消息的列表中检查了这个错误消息,然后显示如下

<input type="file" name="file[]" multiple="multiple">
@foreach($errors->all() as $error)
    @if($error=="Only PDF, JPEG, PNG are allowed.")
            <span class="help-block"><strong>{{$error}}</strong></span>
    @endif
@endforeach

@foreach($errors->all()作为$error)
@如果($error==“只允许使用PDF、JPEG、PNG。”)
{{$error}}
@恩迪夫
@endforeach

感谢大家,

我已经试过了。此给定错误未定义偏移量:0验证没有问题。我对错误信息有问题一旦你使用这个答案,只要打印整个
$errors
来查看这些信息,你就会明白。当我打印所有错误时,会有验证错误,但是如何从那里选择错误只需先检查你在使用
@if($errors->has('file.0'){{$errors->时得到的任何信息即可('file.0')}@endif
'file.*' => 'Only PDF, JPEG, PNG are allowed.'
<input type="file" name="file[]" multiple="multiple">
@foreach($errors->all() as $error)
    @if($error=="Only PDF, JPEG, PNG are allowed.")
            <span class="help-block"><strong>{{$error}}</strong></span>
    @endif
@endforeach