From f6d00383cbc96ab0e00e49bebd5b32cb9f638306 Mon Sep 17 00:00:00 2001 From: Edmondlang Date: Wed, 16 Apr 2025 14:40:07 +0800 Subject: [PATCH] Safely clean output buffer only if it's started and not already cleaned --- .../ExportCustomersToExcelController.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Exports/ExportCustomersToExcelController.php b/app/Http/Controllers/Exports/ExportCustomersToExcelController.php index 27fcef03..e057d104 100644 --- a/app/Http/Controllers/Exports/ExportCustomersToExcelController.php +++ b/app/Http/Controllers/Exports/ExportCustomersToExcelController.php @@ -60,14 +60,20 @@ class ExportCustomersToExcelController } } - public function groupTransaction(Request $request){ - $exportsTransactions = new ExportsGroupTransactions($request); - $response = $exportsTransactions->download('group-transactions.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']); - // Safely clean output buffer if it exists - if (ob_get_level()) { + public function groupTransaction(Request $request) + { + // Safely clean output buffer only if it's started and not already cleaned + while (ob_get_level() > 0) { ob_end_clean(); } - return $response; + + $exportsTransactions = new ExportsGroupTransactions($request); + + return $exportsTransactions->download( + 'group-transactions.xls', + \Maatwebsite\Excel\Excel::XLS, + ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'] + ); } public function totalOrders(Request $request){