services.*.not_taxable could be resolved by some lookup rules, maybe an accessor. I guess I don't understand the validation here.
Nov 22, 2020
10
Level 19
I need to validate a field which cannot be true if another field is greater than 0
I need to validate a checkbox field that MUST be false if another field is greater than 0, but can be false or true in other situations.The field is passed by request in array.
Example of request form:
'name' => 'Invoice 1',
'number' => 'Inv-001'
'services' => [
0 => [
'name' => 'Test 2'
'vat' => 10.00,
'unit_price' => 40.00,
'quantity' => 5,
'not_taxable' => false
],
1 => [
'name' => 'Test 2'
'vat' => 10.00,
'unit_price' => 40.00,
'quantity' => 5,
'not_taxable' => true
],
]
In this example I need not_taxable to be false in services[1] if vat is greather than 0. This is my rule for this field :
'services.*.not_taxable' => 'sometimes:required|boolean',
Rules as required_if, or required_unless etc are not efficient as they do not make any comparisons whether the field is true or false but only if it is passed by the request.
Please or to participate in this conversation.