'boulders_per' => 'numeric',
'fine_soil_per' => 'numeric',
Rule::sometimes(function () {
$sum = $this->input('boulders_per', 0) + $this->input('fine_soil_per', 0);
return $sum !== 100;
}),
used requiredif bt these fileds are not always required to be filled and using sometimes its shows error
"message": "Method IlluminateValidationRule::sometimes does not exist.",
2
Answers
You might try to implement this on top of your controller(or wherever you use that function):
use IlluminateSupportFacadesValidator;
Method : 1
You must use Custom Validation Rules for single attribute validations.
There is a provision in After Validation Hooks where such kind of complex validation can be written
Method : 2
Your can convert the value from an array to a collection and use the sum collect method