formService = $formService; $this->sector = $sector; $this->code = $code; $this->inventoryYear = $inventoryYear ?? date('Y'); $this->lands = $lands; $this->instansi = $instansi; } public function collection(Collection $rows) { $data = []; for ($i = 0; $i < count($rows); $i++) { $land1 = strtolower($this->lands[$i]); $items = $rows[$i]->toArray(); $items = array_values($items); for ($j = 0; $j < count($items); $j++) { if ($j !== 0) { $land2 = strtolower($this->lands[$j - 1]); $data["{$land1}_{$land2}"] = getFormattedValue($items[$j]); } } } $this->formService->save($this->sector, $this->code, $this->inventoryYear, $data, $this->instansi); } }