仅当用户在Laravel中的字段中输入一些值时,如何执行验证检查

时间:2018-04-25 02:02:57

标签: laravel validation

我是Laravel的新人。我想仅在用户在密码文本字段中输入一些值时才执行验证检查。否则,请勿对密码字段执行验证检查。

我搜索了类似的问题,但没有找到任何满意的答案。

提前感谢您的帮助。

更新:这是我的验证代码

if x_egg + egg_radius > x_pos and \
   x_egg  + egg_radius < x_pos + x_size and \
   y_egg - egg_radius >= y_pos and \
   y_egg + egg_radius <= y_pos + y_size:
    caught_egg = True
    y_egg = 0
    x_egg = InitEgg()

2 个答案:

答案 0 :(得分:1)

不要使用required规则

 "password" => "min:6 | max:12"

只有填写了密码字段,密码的长度才为6到12个。

答案 1 :(得分:-1)

如果您愿意,可以尝试使用此代码:

if(!empty($request->input('password'))){
  // perform the validation with password
} else{
  // perform the validation without password
}
相关问题