I've got the following validation rules:
[
MenuItem::MENU_ITEM_NAME => 'required|unique:menu_items,name',
MenuItem::MENU_ITEM_DESCRIPTION => 'nullable',
MenuItem::MENU_ITEM_CATEGORY => 'required|exists:categories,id',
MenuItem::MENU_ITEM_SIDE => 'nullable|boolean',
MenuItem::MENU_ITEM_SIDE_ONLY => 'nullable|boolean',
MenuItem::MENU_ITEM_IMAGE => 'nullable',
MenuItem::MENU_ITEM_AVAILABLE => 'nullable|boolean',
MenuItem::MENU_ITEM_ACTIVE => 'nullable|boolean',
MenuItem::MENU_ITEM_PRICING => 'required',
]
they work fine until this test case that I need to implement:
Pricing aka MenuItem::MENU_ITEM_PRICING is an array of arrays. I need to check that when MenuItem::MENU_ITEM_SIDE is passed as true then the pricing array must contain a subarray with the some values for that specific item.
Ex:
[
MenuItem::MENU_ITEM_SIDE => false,
MenuItem::MENU_ITEM_PRICING => []
]
the previous example is valid. But:
[
MenuItem::MENU_ITEM_SIDE => true,
MenuItem::MENU_ITEM_PRICING => []
]
is invalid, it should be:
[
MenuItem::MENU_ITEM_SIDE => false,
MenuItem::MENU_ITEM_PRICING => [['sideprice' => 2.20]]
]
How can I check (within my FormRequest class) that if MenuItem::MENU_ITEM_SIDE == true then MenuItem::MENU_ITEM_PRICING should contain a subarray with a key named sideprice?