geoJsonPath = $geoJsonPath; $this->excelPath = $excelPath; } public function getGeoJsonPivotNames():Collection { $geoJson = json_decode(file_get_contents($this->geoJsonPath), true); $pivotNames = collect([]); foreach ($geoJson['features'] as $feature) { $pivotNames->add( $feature['properties']['field']); } return $pivotNames->unique(); } public function getHarvestDataPivotNames():Collection { $excelData = Excel::toCollection(new \App\Imports\ExcelFileImport(), $this->excelPath); $sheetOne = $excelData->toArray()[0]; $fieldNames = collect([]); foreach ($sheetOne as $rowIndex => $row) { if ($rowIndex === 0) { foreach ($row as $columnIndex => $cell) { if (strtolower($cell) === 'field') { $fieldColumnName = $columnIndex; } } continue; } $fieldNames->add(trim($row[$fieldColumnName])); } return $fieldNames->unique(); } public function getCommonPivotNames():Collection { return $this->getGeoJsonPivotNames()->intersect($this->getHarvestDataPivotNames()); } public function getGeoJsonPivotNamesNotInHarvest():Collection { return $this->getGeoJsonPivotNames()->diff($this->getHarvestDataPivotNames()); } public function getHarvestPivotNamesNotInGeoJson():Collection { return $this->getHarvestDataPivotNames()->diff($this->getGeoJsonPivotNames()); } public function hasErrors():bool { return $this->getGeoJsonPivotNamesNotInHarvest()->isNotEmpty() || $this->getHarvestPivotNamesNotInGeoJson()->isNotEmpty(); } }