gpt4 book ai didi

laravel - 如何允许 Laravel 数字验证为空值

转载 作者:行者123 更新时间:2023-12-02 18:30:01 26 4
gpt4 key购买 nike

如何设置Laravel5.2不需要数字验证?我刚刚使用了此代码,但是当我不发送值或选择框未选择项目时,我出现错误,val 字段大多数是数字...我需要如果请求没有床输入,则不要理会床。下床验证...

$this->validate($request, [
'provinces_id' => 'required|numeric',
'type' => 'required',
'bed' => 'numeric',
]);

最佳答案

如果我没理解错的话,您正在寻找 sometimes规则:

'bed' => 'sometimes|numeric',

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 to your rule list

关于laravel - 如何允许 Laravel 数字验证为空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40215339/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com