'required', 'based_on' => ['required', Rule::in([TaxClass::SHIPPING_ADDRESS, TaxClass::BILLING_ADDRESS, TaxClass::STORE_ADDRESS])], 'rates.*.name' => 'required_with:rates.*.rate', 'rates.*.rate' => ['required_with:rates.*.name', 'numeric', 'min:0', 'max:9999'], ]; } /** * Get data to be validated from the request. * * @return array */ public function validationData() { return request()->merge([ 'rates' => $this->filter($this->rates ?? []), ])->all(); } /** * Filter tax rates. * * @param array $rates * @return array */ private function filter($rates = []) { return array_filter($rates, function ($rate) { return ! is_null($rate['name']) || ! is_null($rate['rate']); }); } }