file('file')->getPathname())), 3600); //parse CSV $csv_array = $this->getCsvData(file_get_contents($request->file('file')->getPathname())); $class_map = $this->getEntityMap($request->input('entity_type')); $data = [ 'hash' => $hash, 'available' => $class_map::importable(), 'headers' => array_slice($csv_array, 0, 2) ]; return response()->json($data); } public function import(ImportRequest $request) { CSVImport::dispatch($request->all(), auth()->user()->company()); return response()->json(['message' => 'Importing data, email will be sent on completion'], 200); } private function getEntityMap($entity_type) { return sprintf('App\\Import\\Definitions\%sMap', ucfirst($entity_type)); } private function getCsvData($csvfile) { if (! ini_get('auto_detect_line_endings')) { ini_set('auto_detect_line_endings', '1'); } $csv = Reader::createFromString($csvfile); $stmt = new Statement(); $data = iterator_to_array($stmt->process($csv)); if (count($data) > 0) { $headers = $data[0]; // Remove Invoice Ninja headers if (count($headers) && count($data) > 4) { $firstCell = $headers[0]; if (strstr($firstCell, config('ninja.app_name'))) { array_shift($data); // Invoice Ninja... array_shift($data); // array_shift($data); // Enitty Type Header } } } return $data; } }