Please post the JSON of your request params so we can get a better idea of what the structure of your Request looks like.
required if array of checkbox is checked
I am creating variants for products. For each variant, if manage stock checkbox is checked then the user must enter the stock but at the time of validation stock quantity asked for each variant.
$validate['variant_manage_stock.*'] = ['sometimes', 'accepted'];
$validate['variant_stock_quantity.*'] = ['required_if:variant_manage_stock.*,1', 'numeric'];
$validate['variant_allow_backorder.*'] = ['required', 'in:no,notify,yes'];
$validate['variant_stock_threshold.*'] = ['required_if:variant_manage_stock.*,1', 'numeric', 'min:1', 'lt:variant_stock_quantity.*'];
I also tried.
$validate['variant_manage_stock.*'] = ['sometimes', 'accepted'];
$validate['variant_stock_quantity.*'] = ['required_with:variant_manage_stock.*,on', 'numeric'];
$validate['variant_allow_backorder.*'] = ['required', 'in:no,notify,yes'];
$validate['variant_stock_threshold.*'] = ['required_with:variant_manage_stock.*,on', 'numeric', 'min:1', 'lt:variant_stock_quantity.*'];
validation errors:- The variant_stock_quantity.0 must be a number.
The variant_stock_quantity.1 must be a number. The variant_stock_quantity.2 must be a number. The variant_stock_quantity.3 must be a number. The variant_stock_quantity.4 must be a number. The variant_stock_quantity.5 must be a number. The variant_stock_threshold.0 must be less than variant_stock_quantity.0. The variant_stock_threshold.1 must be less than variant_stock_quantity.1. The variant_stock_threshold.2 must be less than variant_stock_quantity.2. The variant_stock_threshold.3 must be less than variant_stock_quantity.3. The variant_stock_threshold.4 must be less than variant_stock_quantity.4. The variant_stock_threshold.5 must be less than variant_stock_quantity.5.
my rule for validation should be:
$validate['variant_manage_stock.*'] = ['sometimes', 'accepted'];
$validate['variant_stock_quantity.*'] = ['nullable', 'numeric', 'min:2'];
$validate['variant_allow_backorder.*'] = ['required', 'in:no,notify,yes'];
$validate['variant_stock_threshold.*'] = ['nullable', 'numeric', 'min:1', 'lt:variant_stock_quantity.*'];
Thanks to all laracasters for their valuable time.
Please or to participate in this conversation.