I have a Laravel Request where I need to validate the keys from an array. The keys are the productId and I am checking if the product belongs to the user.
Here is an example of products at the POST request:
[
8 => [
'quantity' => 10,
'discount' => 10
],
9 => [
'quantity' => 10,
'discount' => 10
]
]
And bellow is the Request rules. Is it possible to check on the keys?
public function rules()
{
return [
'product.*' => 'required|exists:recipes,id,user_id,' . $this->user()->id,
'product.*.quantity' => 'required|numeric|min:0',
'product.*.discount' => 'required|numeric|min:0'
];
}