Skip to content

Commit f8cc424

Browse files
committed
fix csv file validation after import
1 parent 5cd3761 commit f8cc424

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

src/Concerns/HasCsvProperties.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public function handleCsvProperties(): array|MessageBag
5454
Log::warning($exception->getMessage());
5555

5656
return $this->addError(
57-
'file_error',
58-
__('Your CSV file has error/errors, or is empty. Please check, and try again')
57+
'file',
58+
__('The file has error/errors, Please check, and try again')
5959
);
6060
}
6161
}

src/Http/Livewire/CsvImporter.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,20 @@ protected function rules()
114114

115115
protected function setCsvProperties()
116116
{
117+
if (! $this->handleCsvProperties() instanceof MessageBag) {
118+
return [
119+
$this->fileHeaders,
120+
$this->fileRowCount
121+
] = $this->handleCsvProperties();
122+
}
123+
117124
$this->withValidator(function (Validator $validator) {
118125
$validator->after(function ($validator) {
119-
if ($this->handleCsvProperties() instanceof MessageBag) {
120-
$validator->errors()->merge(
121-
$this->handleCsvProperties()->getMessages()
122-
);
123-
}
126+
$validator->errors()->merge(
127+
$this->handleCsvProperties()->getMessages()
128+
);
124129
});
125130
})->validate();
126-
127-
[$this->fileHeaders, $this->fileRowCount] = $this->handleCsvProperties();
128131
}
129132

130133
protected function importCsv()

tests/CsvImporterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
])
5454
->set('file', $file)
5555
->assertSet('model', $model)
56-
->assertHasErrors(['file_error']);
56+
->assertHasErrors(['file']);
5757
});
5858

5959
it('throws a validation error if the csv file has duplicate headers', function () {
@@ -70,7 +70,7 @@
7070
])
7171
->set('file', $file)
7272
->assertSet('model', $model)
73-
->assertHasErrors(['file_error']);
73+
->assertHasErrors(['file']);
7474
});
7575

7676
it('transfers columnsToMap into an associative array', function () {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy