'How validate an array with a dot in key name ? (Laravel)

How can I validate this array in laravel validation:

"price" => array:1 [▼
           0 => array:1 [▼
                "price.value" => 50
]

I tried to use this, but it does't working:

'price.0.price.value' => ['required']

How can I solve? I want to note that: I have no choice to change the name "price.value".



Solution 1:[1]

As you cannot change the name price.value you have to escape the dot since in Laravel array validation a dot means a nested level. Try to escape the. with \
Your data:

 "price" => array:1 [?
           0 => array:1 [?
                "price.value" => 50
]

Validation rule with dot escaped:

'price.0.price\.value' => ['required']

Solution 2:[2]

Example:

{
  filters: [{field: '', value: ''}]
}

     
'filters' => 'nullable|array',
'filters.*.field' => 'required|max:60',
'filters.*.value' => 'nullable|max:60',
'filters.*.cond' => 'nullable|max:10',

Solution 3:[3]

Try it:

'price.*.value' => 'required'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 ikhee
Solution 3