Add validation to importers to fix invalid/empty columns #222
This commit is contained in:
@@ -83,7 +83,7 @@ class ImportService extends Service
|
||||
{
|
||||
$reader = $this->openCsv($file_path);
|
||||
|
||||
$cols = $importer->getColumns();
|
||||
$cols = array_keys($importer->getColumns());
|
||||
$first_header = $cols[0];
|
||||
|
||||
$first = true;
|
||||
@@ -111,6 +111,14 @@ class ImportService extends Service
|
||||
return trim($val);
|
||||
})->toArray();
|
||||
|
||||
# Try to validate
|
||||
$validator = Validator::make($row, $importer->getColumns());
|
||||
if($validator->fails()) {
|
||||
$errors = 'Error in row '.$offset.','.implode(';', $validator->errors()->all());
|
||||
$importer->errorLog($errors);
|
||||
continue;
|
||||
}
|
||||
|
||||
$importer->import($row, $offset);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user