Good day
I am trying to update the info in database
this is my validation in api resource Controller
if ($this->resourceModel()->getTable() == 'customers') {
$request->validate([
'birthday' => ['required'],
'height' => ['min:3|numeric'],
'weight' => ['min:2|numeric'],
]);
}
on my TS file in angular , I input the height 100 and weight also is 100 to make sure that the validation will meet . However im getting error "The height must be at least 3|numeric characters." and "The weight must be at least 2|numeric characters."
I also tried to parse the string to check if it will fix the problem however im still getting the same error .
If i put four digits example : height - 1000 , weight - 1000 It will proceed , Why is that ? it says min is 3 for height and min for weight is 2 ,
Need help Thanks
CodePudding user response:
Try This
if ($this->resourceModel()->getTable() == 'customers') {
$request->validate([
'birthday' => ['required'],
'height' => ['nullable|numeric|min:3'],
'weight' => ['nullable|numeric|min:2'],
]);
}
Change nullable to required as per requirements.. You can also use Grater than(gt) validation rule e.g
'height' => ['required|numeric|gt:2']..
CodePudding user response:
You don't require the square brackets around your validation rules when you define them all in a single string, only when you define each rule individually.
$request->validate([
'birthday' => 'required',
'height' => 'min:3|numeric',
'weight' => 'min:2|numeric'
]);
Or
$request->validate([
'birthday' => ['required'],
'height' => ['min:3', 'numeric'],
'weight' => ['min:2', 'numeric'],
]);