Try an array, and is the required word needed?
Also try laravel validation for the numbers.
https://livewire.laravel.com/docs/validation#using-laravel-rule-objects
Hello,
I have a very strange behavior with some rules.
#[Validate('required', message: 'Le nombre de portions est obligatoire.', onUpdate: false)]
#[Validate('integer', message: 'Le nombre de portions doit être un nombre entier.', onUpdate: false)]
#[Validate('min:1', message: 'Le nombre de portions doit être supérieur ou égal à 1.', onUpdate: false)]
#[Validate('max:255', message: 'Le nombre de portions doit être inférieur ou égal à 255.', onUpdate: false)]
public $portions = null;
According to me, these rules should work, but the problem is that they don't work.
required : ok
integer : ok
min:1 : not working
max:255 : not working
When I type a negative value or a value greater than 255, the validation is successful whereas it should generate an error.
Do you have any idea why it doesn't work ?
Thanks a lot.
V
I have searched why the rules I presented in the post didn't work.
In fact they work fine, but only if I don't filter the fields. In the form, before validation, I apply a filter to remove all unnecessary spaces and return null if the string is null. The problem is that I filtered also the numeric values, but it wasn't a good idea.
Now I don't filter the numeric values any more and these filters work fine.
#[Validate('required', message: 'Le nombre de portions est obligatoire.', onUpdate: false)]
#[Validate('integer', message: 'Le nombre de portions doit être un nombre entier.', onUpdate: false)]
#[Validate('min:1', message: 'Le nombre de portions doit être supérieur ou égal à 1.', onUpdate: false)]
#[Validate('max:255', message: 'Le nombre de portions doit être inférieur ou égal à 255.', onUpdate: false)]
public $portions = null;
Please or to participate in this conversation.