fud*_*udo 6 validation rules laravel eloquent option-type
我的请求中有两个整数字段需要验证,min_height
和max_height
,两者都是可选的,但必须min_height
小于max_height
并max_height
希望(当然)大于min_height
。
使用验证规则如下
'min_height' => ['nullable', 'integer', 'lt:max_height'],
'max_height' => ['nullable', 'integer', 'gt:min_height'],
Run Code Online (Sandbox Code Playgroud)
当其中一个存在但另一个不存在时,这当然会给我带来错误,因为lt
/gt
验证规则针对null
请求字段进行检查。
仅当其他字段存在时,我如何才能进行lt
检查?gt
有没有办法通过内置验证规则来实现这一点,或者我是否必须实现自定义验证器?
可能我还不够清楚:我的两个字段都是可为空且彼此独立的min_height
,所以接收和不接收都可以max_height
,反之亦然:这使得规则required_with
不适合我的用例。