client()->service()->statement( $request->only(['start_date', 'end_date', 'show_payments_table', 'show_aging_table', 'show_credits_table', 'status']) ); if ($pdf && $request->query('download')) { return response()->streamDownload(function () use ($pdf) { echo $pdf; }, 'statement.pdf', ['Content-Type' => 'application/pdf']); } if ($pdf) { return response($pdf, 200)->withHeaders([ 'Content-Type' => 'application/pdf', ]); } return response()->json(['message' => 'Something went wrong. Please check logs.']); } }