Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Jobs/DataTableExportJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Http\File;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Arr;
Expand Down Expand Up @@ -179,6 +180,10 @@ public function handle()
}

$writer->close();

if($this->getS3Disk()) {
Storage::disk($this->getS3Disk())->put($filename, (new File($path))->getContent());
}
}

/**
Expand All @@ -189,6 +194,14 @@ protected function getDisk(): string
return strval(config('datatables-export.disk', 'local'));
}

/**
* @return string
*/
protected function getS3Disk(): string
{
return strval(config('datatables-export.s3_disk', ''));
}

/**
* @param \Yajra\DataTables\Services\DataTable $dataTable
* @return \Illuminate\Support\Collection<array-key, Column>
Expand Down
14 changes: 12 additions & 2 deletions src/Livewire/ExportButtonComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ public function updateExportProgress(): ?StreamedResponse

public function downloadExport(): StreamedResponse
{
return Storage::disk($this->getDisk())
->download($this->batchJobId.'.'.$this->getType(), $this->getFilename());
if($this->getS3Disk()) {
return Storage::disk($this->getS3Disk())->download($this->batchJobId.'.'.$this->getType(), $this->getFilename());
}
return Storage::disk($this->getDisk())->download($this->batchJobId.'.'.$this->getType(), $this->getFilename());
}

protected function getType(): string
Expand Down Expand Up @@ -110,4 +112,12 @@ protected function getDisk(): string

return $disk;
}

protected function getS3Disk(): string
{
/** @var string $disk */
$disk = config('datatables-export.s3_disk', '');

return $disk;
}
}
10 changes: 10 additions & 0 deletions src/config/datatables-export.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@
*/
'disk' => 'local',

/*
|--------------------------------------------------------------------------
| Use S3 for final file destination
|--------------------------------------------------------------------------
|
| After generating the file locally, it can be uploaded to s3.
|
*/
's3_disk' => '',

/*
|--------------------------------------------------------------------------
| Default Date Format
Expand Down