Skip to content

Commit 3ae8fa9

Browse files
committed
Use disk instead of hardcoded path
1 parent fd6a438 commit 3ae8fa9

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/Jobs/DataTableExportJob.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
use Illuminate\Support\Arr;
1818
use Illuminate\Support\Facades\Auth;
1919
use Illuminate\Support\Facades\File;
20+
use Illuminate\Support\Facades\Storage;
2021
use Illuminate\Support\Str;
2122
use PhpOffice\PhpSpreadsheet\Shared\Date;
23+
use Yajra\DataTables\Exceptions\Exception;
2224
use Yajra\DataTables\Html\Column;
2325
use Yajra\DataTables\Services\DataTable;
2426

@@ -74,15 +76,14 @@ public function handle()
7476
$dataTable = app()->call([$oTable, 'dataTable'], compact('query'));
7577
$dataTable->skipPaging();
7678

77-
$exportPath = config('datatables-export.path', storage_path('app/exports'));
79+
$type = Str::startsWith(request('exportType'), Type::CSV) ? Type::CSV : Type::XLSX;
80+
$disk = config('datatables-export.disk', 'local');
81+
$filename = $this->batchId.'.'.$type;
7882

79-
if (! File::isDirectory($exportPath)) {
80-
File::makeDirectory($exportPath);
81-
}
83+
$path = Storage::disk($disk)->path($filename);
8284

83-
$type = Str::startsWith(request('exportType'), Type::CSV) ? Type::CSV : Type::XLSX;
8485
$writer = WriterEntityFactory::createWriter($type);
85-
$writer->openToFile($exportPath.'/'.$this->batchId.'.'.$type);
86+
$writer->openToFile($path);
8687

8788
$columns = $oTable->html()->getColumns()->filter->exportable;
8889
$writer->addRow(

src/Livewire/ExportButtonComponent.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public function updateExportProgress()
4848

4949
public function downloadExport()
5050
{
51-
return Storage::download('exports/'.$this->batchJobId.'.'.$this->getType(), $this->getFilename());
51+
$disk = config('datatables-export.disk', 'local');
52+
53+
return Storage::disk($disk)->download($this->batchJobId.'.'.$this->getType(), $this->getFilename());
5254
}
5355

5456
public function render()

src/config/datatables-export.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030

3131
/*
3232
|--------------------------------------------------------------------------
33-
| Export path
33+
| Export filesystem disk
3434
|--------------------------------------------------------------------------
3535
|
36-
| Export path where generated files will be stored.
36+
| Export filesystem disk where generated files will be stored.
3737
|
3838
*/
39-
'path' => storage_path('app/exports'),
39+
'disk' => 'local',
4040

4141
/*
4242
|--------------------------------------------------------------------------

0 commit comments

Comments
 (0)