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

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -