我有一个字段“图像”,类型是文件,只需要验证图像是否被选中,意味着它也可以是空的.
我试过了:’avatar’=> ‘mimes:jpeg,jpg,png,gif | max:100000’,但所以它也是必需的.
我仍然尝试使用参数,有时但仍然需要该字段.
如何仅在选择图像时才能验证它?
解决方法:
>如果您想要使用的输入数组中可能不存在“avatar”字段:
‘avatar’=> ‘有时候|默剧:JPEG,JPG,PNG,GIF | MAX:100000’
In some situations, you may wish to run validation checks against a field only if that field is present in the input array. To quickly accomplish this, add the sometimes rule.
>如果“avatar”字段绝对位于输入数组中,并且它的值将为null,则您希望使用:
‘avatar’=> ‘可空|默剧:JPEG,JPG,PNG,GIF | MAX:100000’
The field under validation may be null. This is particularly useful when validating primitive such as strings and integers that can contain null values. To quickly accomplish this, add the nullable rule.
标签:laravel-5-3,php,laravel,laravel-5
来源: https://codeday.me/bug/20190724/1523761.html