Skip to content

Commit e3daae6

Browse files
authored
Merge pull request #21 from septoctobre/feat/xslx-import
Loosen the restriction on file type
2 parents ade206f + a1b98e5 commit e3daae6

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/Http/Controllers/ImportController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct()
2727
public function preview(NovaRequest $request, $file)
2828
{
2929
$import = $this->importer
30-
->toCollection($this->getFilePath($file), null, 'Csv')
30+
->toCollection($this->getFilePath($file), null)
3131
->first();
3232

3333
$headings = $import->first()->keys();
@@ -37,10 +37,10 @@ public function preview(NovaRequest $request, $file)
3737
$sample = $import->take(10)->all();
3838

3939
$resources = collect(Nova::$resources);
40-
40+
4141
$resources = $resources->filter(function ($resource) {
4242
$static_vars = (new \ReflectionClass((string) $resource))->getStaticProperties();
43-
43+
4444
if(!isset($static_vars['canImportResource'])) {
4545
return true;
4646
}
@@ -87,7 +87,7 @@ public function import(NovaRequest $request, $file)
8787
->setAttributeMap($attribute_map)
8888
->setRules($rules)
8989
->setModelClass($model_class)
90-
->import($this->getFilePath($file), null, 'Csv');
90+
->import($this->getFilePath($file), null);
9191

9292
if (! $this->importer->failures()->isEmpty() || ! $this->importer->errors()->isEmpty()) {
9393
return response()->json(['result' => 'failure', 'errors' => $this->importer->errors(), 'failures' => $this->importer->failures()]);

src/Http/Controllers/UploadController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ public function handle(NovaRequest $request)
1919
])->validate();
2020

2121
$file = $request->file('file');
22+
$extension = $file->getClientOriginalExtension();
2223

2324
try {
24-
(new Importer)->toCollection($file, null, 'Csv');
25+
(new Importer)->toCollection($file, null);
2526
} catch (\Exception $e) {
2627
return response()->json(['result' => 'error', 'message' => 'Sorry, we could not import that file'], 422);
2728
}
2829

2930
// Store the file temporarily
30-
$hash = File::hash($file->getRealPath());
31+
$hash = File::hash($file->getRealPath()).".".$extension;
3132

3233
$file->move(storage_path('nova/laravel-nova-import-csv/tmp'), $hash);
3334

0 commit comments

Comments
 (0)