path($this->import->filename); $reader = new Xlsx(); $spreadsheet = $reader->load($path); $this->sheet = $spreadsheet->getActiveSheet(); $this->rowIterator = $this->sheet->getRowIterator(); } protected function rowToArray($row): array { $cellIterator = $row->getCellIterator(); $cellIterator->setIterateOnlyExistingCells(FALSE); $row_content = []; $keys = array_values($this->headers); $i = 0; foreach ($cellIterator as $cell) { $row_content[$keys[$i++]] = $cell->getValue(); } return $row_content; } /** * @param array $headers * @return bool */ protected function checkHeaders(array $headers): bool { foreach ($headers as $k => $header) { $headers[$k] = Str::before($header, "\n"); } return $headers == array_keys($this->headers); } protected function findId(string $tableNameCol, string $value): string { list($table, $column) = explode('.', $tableNameCol); $model = DB::table($table) ->where($column, $value) ->first(); if (!$model) { echo $this->import->log("SKIP: no {$tableNameCol} {$value} found!", 'WARNING'); } return $model?->id ?? ''; } }