headers->set('Authorization', 'Bearer ' . $token); } public function export(Request $request) { $exportsTransactions = new ExportsCustomersWalletTransactionHistory($request); $exportFileName = $request->route('marking') . '-wallet-' . ($request->route('is_precise') == 'true' ? 'precise-' : '') . 'transaction-history.xls'; $filesystemDriver = Storage::getDefaultDriver(); if($filesystemDriver === 's3'){ return response([ 'src' => $this->S3($exportFileName, $exportsTransactions) ]); } else{ $response = $exportsTransactions->download($exportFileName, Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']); ob_end_clean(); return $response; } } private function S3($exportFileName, $exportableObject){ //Step 1: Upload to S3 $filePathForS3 = 'temp/' . $exportFileName; $exportableObject->store($filePathForS3, 's3'); //Step 2: Return temporary URL from S3 $temporaryUrl = Storage::disk('s3')->temporaryUrl( $filePathForS3, Carbon::now()->addMinutes(10) ); return $temporaryUrl; } }