Laravel 5 最小长度验证规则取决于另一个在laravel中不起作用的属性
上面的代码显示我的请求类此验证规则不起作用,即使我将基本占用率设为2,将最大占用率设为10,这仍将显示错误 这两个值在数据库中都是int(11)Laravel 5 最小长度验证规则取决于另一个在laravel中不起作用的属性,laravel-5,Laravel 5,上面的代码显示我的请求类此验证规则不起作用,即使我将基本占用率设为2,将最大占用率设为10,这仍将显示错误 这两个值在数据库中都是int(11) 您需要通过扩展验证类来添加自定义验证规则。我现在无法测试,但请尝试以下方法: class AddRoomRequest extends Request { public function rules() { return [ 'name' => 'required|min:2|max:10
您需要通过扩展验证类来添加自定义验证规则。我现在无法测试,但请尝试以下方法:
class AddRoomRequest extends Request {
public function rules()
{
return [
'name' => 'required|min:2|max:1000',
'base_occupancy' => 'required|integer|min:0|max:100',
'max_occupancy' => 'required|integer|min:0|max:100'
];
}
}
您的max_入住率规则将是:
Validator::extend('greater_than', function($attribute, $value, $parameters) {
if (isset($parameters[0])) {
return intval($value) > intval($parameter[0]);
} else {
return false;
}
}
尝试使用size:2 | size:1000返回的“$parameters”数组为:array:1[▼ 0=>“基本占用率”]。所以我没有得到基本占用率的值来检查“大于”条件。
'max_occupancy' => 'required|integer|max:100|greater_than:base_occupancy'