Export file directly from Laravel Vapor without going through S3 bucket

This commit is contained in:
Dillon Ngo
2024-06-17 10:08:57 +08:00
parent acbdd79677
commit b24c9149ce
@@ -58,9 +58,19 @@ class ExportCustomersToExcelController
public function paymentTransactions(Request $request){
$exportsTransactions = new ExportsPaymentTransactions($request);
$response = $exportsTransactions->download('payment-transactions.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
$exportFileName = 'payment-transactions.xls';
$filesystemDriver = Storage::getDefaultDriver();
if($filesystemDriver !== 's3'){
if($filesystemDriver === 's3'){
$exportDirectory = storage_path('app/export'); // Update this with the actual directory path
if (!file_exists($exportDirectory)) {
mkdir($exportDirectory, 0755, true);
}
$localPath = $exportDirectory . '/' . $exportFileName;
$response = $exportsTransactions->store($localPath, null, Excel::XLS);
return response()->file($localPath, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
}
else{
$response = $exportsTransactions->download($exportFileName, Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
ob_end_clean();
}
return $response;
@@ -118,3 +128,4 @@ class ExportCustomersToExcelController
return $response;
}
}