$row) { // Skip the header row if ($key === 0) { continue; } // Extract data from the current row $number = $row[0]; $subdistrictName = $row[1]; $altitudeValue = $row[2]; $phSoilValue = $row[3]; // Create or update the Subdistrict $subdistrict = Subdistrict::updateOrCreate([ 'subdistrict' => $subdistrictName, ]); // Create or update the Altitude $altitude = Altitude::updateOrCreate([ 'subdistrict_id' => $subdistrict->id, 'altitude' => $altitudeValue, ]); // Create or update the pH Soil $phSoil = PhSoil::updateOrCreate([ 'subdistrict_id' => $subdistrict->id, 'ph_soil' => $phSoilValue, ]); } } }