Complex Array Validation Rules |
I'm trying to develop some complex rules to validate a JSON document being sent to the codeigniter script. I think I might have a misunderstanding of the specific rules.
For example, here is a snippet of the validation rules I'm currently using: PHP Code: "fees" => [ My expectation is that the fees.*.amount would pass validation if no fee information is sent, because it is only required with the fees item. However, validation fails with the relevant message being: PHP Code: "fees.*.amount": "The fee amount must be a number.", I don't get an error about the name. So, I'm missing something. Is the permit_empty also required for the fee amount? Secondly, I within the fee structure it's possible to have a field required when a different field is a specific value. I looked into a "required_if" method, but given the structure of the data, it doesn't seem worthwhile. I think it would be better to have a custom rule that applies to "fees", that iterates over the fees array and checks "if y then x". Is it possible to set a custom error message from within a class? For example, a method might look like: PHP Code: class FeeRules extends Rules The callable and closure rules look like they have an error parameter, but this does not... |
Messages In This Thread |
Complex Array Validation Rules - by rockinmusicgv - 10-22-2024, 08:47 AM
RE: Complex Array Validation Rules - by rockinmusicgv - 10-24-2024, 06:43 AM
RE: Complex Array Validation Rules - by rockinmusicgv - 10-25-2024, 09:00 AM
RE: Complex Array Validation Rules - by bekeanloise - 01-01-2025, 11:56 PM
RE: Complex Array Validation Rules - by rockinmusicgv - 01-20-2025, 11:58 AM
|