我有一个表单,将多个输入字段发送到Laravel 5中的控制器进行验证,其中包括文件name="arquivos[]"
<input>
字段。我想像以前一样一次性解决所有的验证问题,但似乎它失败了,因为它收到了一个文件数组而不是单个文件。表单代码如下:
{!! Form::open(['route' => 'posts.store', 'enctype' => 'multipart/form-data']) !!}
...other inputs
{{ Form::file('arquivos[]', array('class' => 'novo-post-form-item', 'required'=>'','multiple' => '')) }}
{!! Form::close() !!}
在我的 posts.store
函数中:
$this->validate($request, array(
'arquivos' => 'required|mimes:image/jpeg,image/png,image/gif,video/webm,video/mp4,audio/mpeg',
'assunto' => 'max:255',
'conteudo' => 'required|max:65535'
));
注:我不知道为什么在验证器中必须指定没有[]
的输入名称,但是它以这种方式工作...
这个问题类似于我在stackoverflow上找到的一些问题,但这次我想问有没有适用于Laravel 5的解决方案。看起来,这个validate
方法期望一个单个的文件输入字段。提前致谢。
file --mime-type filename
它会返回我放在validate
上的相同 mime 类型,但它正在失败验证,不允许继续进行... 我在代码上做错了什么吗? - Fnrmimetypes
验证规则。 - aceraven777