Refactor readFiles method to dynamically set file path and improve file handling
This commit is contained in:
@@ -120,9 +120,11 @@ class SapFileController extends Controller
|
||||
// 'files' => $data,
|
||||
// ]);
|
||||
|
||||
$fileName = 'RMGLAS02-1725800-1.txt';
|
||||
//$fileName = 'RMGLAS02-1725800-1.txt';
|
||||
$fileName = array_values($files)[0];
|
||||
$filePath = $path . '/' . $fileName;
|
||||
|
||||
$lines = file($fileName, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
$lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
if (!$lines) {
|
||||
return response()->json(['status' => 'ERROR', 'message' => 'File is empty'], 400);
|
||||
}
|
||||
@@ -145,14 +147,14 @@ class SapFileController extends Controller
|
||||
}
|
||||
|
||||
// Insert into database
|
||||
foreach ($rows as $row) {
|
||||
\App\Models\ClassCharacteristic::create($row);
|
||||
}
|
||||
foreach ($rows as $row) {
|
||||
\App\Models\ClassCharacteristic::create($row);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => 'SUCCESS',
|
||||
'rows_imported' => count($rows),
|
||||
]);
|
||||
return response()->json([
|
||||
'status' => 'SUCCESS',
|
||||
'rows_imported' => count($rows),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user