Laravel max Validator does not work

I am new to Laravel.

Can someone explain why the validator is maxnot working as I expected in this case?

$input = ["schoolSeatsTotal" => '2000'];
$rules = ['schoolSeatsTotal'=>'max:300'];
$validator = Validator::make($input, $rules);
$validator->fails(); //Expected: true, Actual: false. 
+4
source share
1 answer

You have it schoolSeatsTotalas a string. For string data, the maximum value corresponds to the number of characters. Instead, you want to check for an integer.

So change

$input = ["schoolSeatsTotal" => '2000'];

to

$input = ["schoolSeatsTotal" => 2000];

To make sure you check the numbers, do the following:

$rules = ['schoolSeatsTotal'=>'numeric|max:300'];
+6
source

Source: https://habr.com/ru/post/1542519/


All Articles