From 0fd940ffa4204697a0b6659c76c8a6298719ba30 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 14 Mar 2019 15:38:07 -0700 Subject: [PATCH] Check for empty headers in import --- app/Http/Requests/ItemImportRequest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/Http/Requests/ItemImportRequest.php b/app/Http/Requests/ItemImportRequest.php index b25522e786..fdbb5e76f8 100644 --- a/app/Http/Requests/ItemImportRequest.php +++ b/app/Http/Requests/ItemImportRequest.php @@ -43,6 +43,20 @@ class ItemImportRequest extends FormRequest $import->save(); $fieldMappings=[]; if ($import->field_map) { + + // This checks to make sure the field header has been mapped. + // If it hasn't been, it will throw an array_flip error + foreach ($import->field_map as $field => $fieldValue) { + $errorMessage = null; + + if(is_null($fieldValue)){ + $errorMessage = 'All import fields must be mapped.'; + $this->errorCallback($import, $field, $errorMessage); + + return $this->errors; + } + } + // We submit as csv field: column, but the importer is happier if we flip it here. $fieldMappings = array_change_key_case(array_flip($import->field_map), CASE_LOWER); // dd($fieldMappings);