'error', 'message' => 'CSV file not found']; } $handle = fopen($csvPath, 'r'); if (!$handle) { return ['status' => 'error', 'message' => 'Failed to open CSV']; } $header = fgetcsv($handle); $countryData = []; while (($row = fgetcsv($handle)) !== false) { $rowData = array_combine($header, $row); $country = $rowData['country'] ?? null; $city = $rowData['city'] ?? null; $state = $rowData['admin_name'] ?? null; if (!$country || !$city) { continue; } $cityObj = ['city' => $city]; if ($state && $state !== $city) { $cityObj['state'] = $state; } if (!isset($countryData[$country])) { $countryData[$country] = []; } $countryData[$country][] = $cityObj; } fclose($handle); return $this->createResponse('success', $countryData); } }