图像的选择 php,php – 如果选择“图像/文件”,则对字段进行Laravel验证?

我有一个字段“图像”,类型是文件,只需要验证图像是否被选中,意味着它也可以是空的.

我试过了:’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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值