Skip to content

Required if with array and checkboxes #32

@ivansammartino

Description

@ivansammartino

Hello, and first thanks for this great package!
I have an array like this:

[
    'products' => [
        '10' => [
            'quantity' => 8
            'has_notes' => 1
            'notes' => ''
        ],
        '12' => [
            'quantity' => 0
            'notes' => ''
        ],
        '14' => [
            'quantity' => 0
            'notes' => ''
        ],
    ]
]

Basically I'd like that, for each array item, the field 'notes' is required if corresponding 'has_notes' field is present and it's 1 (it's a checkbox, so some items do not have this)

I tried with the following rule, but with no luck:

'products'         => 'array',
'products.*.notes' => 'required_if:products.*.has_notes,1',

Is there a way to do this or do I have to create a custom rule?
Thanks :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions