Safely clean output buffer only if it's started and not already cleaned

This commit is contained in:
Edmondlang
2025-04-16 14:40:07 +08:00
parent 33dfdde9a0
commit f6d00383cb
@@ -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){