我目前在一個窗體中工作。Laravel多個文件上傳驗證
我有多個文件上傳驗證的問題。我只有一個表單允許多個文件上傳。
<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
當默劇式的驗證拋出錯誤,我不能夠顯示錯誤消息。 在這裏,在這種情況下,由於在驗證索引1
失敗引發錯誤的$error->first(file.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.
任何人都有這個想法。任何幫助表示讚賞。
謝謝,
我已經嘗試過這一點。這給錯誤**未定義偏移量:0 ** –
請仔細閱讀,它一定會解決您的問題。 –
https://laracasts.com/discuss/channels/general-discussion/array-validation-is-not-working/replies/125729 –