Laravel Custom Validation with Array as Parameter -
newbie here. can me getting parameter in custom validation.
here validation rule :
['materials.*.receive_quantity' => 'lessthan:materials.*.quantity'] here custom validation :
validator::extend('lessthan', function ($attribute, $value, $parameters, $validator) { return $value <= $parameters[0]; }); when dd($parameters) return string 'materials.*.quantity'. tia.
first, you'll need 5.4.18 release. then, try code:
validator::extenddependent('lessthan', function ($attribute, $value, $parameters, $validator) { return $value <= array_get($validator->getdata(), $parameters[0]); }); and may @ pull request more explanations , examples: pr#18564
p.s. , may typo in code: rule name "lessthan", use "<=" operator instead of "<".
Comments
Post a Comment