比较数值的规则

Rule to compare numeric values

我有这条规则"gt:registration_type_minimum",因此用户需要在字段"registration_type_maximum"中输入一个大于字段"registration_type_minimum"中引入的值的值。

但是如果在 registration_type_minimum 字段中引入值“2”并且在 registration_type_maximum 字段中引入值“1”,则消息不会出现。

$rules = [
  ...
    'registration_type_minimum' => 'nullable|integer|min:0',
    'registration_type_maximum' => 'nullable|gt:registration_type_minimum|integer|min:0',
];

$customMessages = [

  ....
    'registration_type_maximum.after_or_equal' => 'The maximum registrations per request needs to be greater then the minimum.',
];

$this->validate($request, $rules, $customMessages);

在请求中出现:

 "registration_type_minimum" => "2"
  "registration_type_maximum" => "1"

但是显示:方法[validateGt]不存在。

gtgte 等规则在 Laravel 5.6 中引入,在 Laravel 5.5 中不可用。要使用此规则,要么升级到 Laravel 5.6,要么在代码库中找到 Laravel 5.6 的函数定义并扩展您的验证器以使用副本。

作为参考,可以在此处找到代码:

https://github.com/laravel/framework/blob/5.6/src/Illuminate/Validation/Concerns/ValidatesAttributes.php

以及如何扩展验证器:

https://laravel.com/docs/5.5/validation#custom-validation-rules