*/ protected function rawMaterialPriceRules(string $pricesKey = 'prices', ?int $rawMaterialId = null): array { $rules = [ "{$pricesKey}" => ['required', 'array', 'min:1'], "{$pricesKey}.*.variant" => ['required', 'string', 'max:200'], "{$pricesKey}.*.price" => ['required', 'integer', 'gt:0'], "{$pricesKey}.*.stock" => ['required', 'numeric', 'decimal:0,4', 'min:0'], ...$this->variantImageRules($pricesKey), ]; if ($rawMaterialId) { $rules["{$pricesKey}.*.id"] = [ 'nullable', 'integer', Rule::exists('raw_material_prices', 'id') ->where('raw_material_id', $rawMaterialId) ->whereNull('deleted_at'), ]; } return $rules; } /** * @return array */ protected function rawMaterialPriceAttributes(string $pricesKey = 'prices'): array { return [ $pricesKey => 'varian', "{$pricesKey}.*.variant" => 'nama varian', "{$pricesKey}.*.price" => 'harga', "{$pricesKey}.*.stock" => 'stok', ...$this->variantImageAttributes($pricesKey, 'foto varian'), ]; } }