Reputation: 1480
I am using this kind of input form in my page:
<input type="number" class="form-control" name="price" maxlength="4">
So as far as I know I can only input a number here and the form will accept a number and in theory send a numeric value to the controller. However setting this validation rule:
$this->validate($request, [
'price' => 'numeric|max:5'
]);
will make the controller not pass over this point, it doesn't even throw an error, the page gets reloaded and that's it. I found out as I removed the 'numeric' from the rule and it all worked. So what am I missing here? is the data passed from the form being passed as test instead?
Upvotes: 3
Views: 2796
Reputation: 7155
you are getting an redirect because the validation fails I assume you don't output anywhere he validation errors.
https://laravel.com/docs/5.4/validation#rule-size
when you use numeric
with max
you apply the following rule which uses size
size:value
The field under validation must have a size matching the given value. For string data, value corresponds to the number of characters. For numeric data, value corresponds to a given integer value. For an array, size corresponds to the count of the array. For files, size corresponds to the file size in kilobytes
which makes anything lower than 5 to be valid.
change the rule instead to
numeric|min:1|max:99999
or
numeric|between:1,99999
Also use something like Debugbar in your development so you can get as much information from errors.
Upvotes: 3