error('File not found: ' . $filePath); return Command::FAILURE; } // Load the Excel file $spreadsheet = IOFactory::load($filePath); $worksheet = $spreadsheet->getSheetByName('doctor intake questions'); if (!$worksheet) { $this->error('Sheet1 not found in the Excel file.'); return Command::FAILURE; } $jsonArray = []; // Iterate through rows starting from the second row (assuming the first row contains headers) foreach ($worksheet->getRowIterator(2) as $row) { $cellIterator = $row->getCellIterator(); $cellIterator->setIterateOnlyExistingCells(false); // Get the data from each cell $label = $cellIterator->current()->getValue(); $cellIterator->next(); $key = $cellIterator->current()->getValue(); $cellIterator->next(); $type = $cellIterator->current()->getValue(); // Add data to the JSON array $jsonArray[] = [ 'label' => $label, 'key' => $key, 'type' => $type, ]; } // Convert the array to JSON $json = json_encode($jsonArray, JSON_PRETTY_PRINT); // Save JSON to a file $outputFilePath = resource_path('js/views/pages/questionere/questions_parse.json'); file_put_contents($outputFilePath, $json); $this->info('JSON data saved to: ' . $outputFilePath); } }