Export add

This commit is contained in:
sayaliparab
2024-06-17 12:34:42 +05:30
parent 1cac85cf94
commit 1904e4aacc
5 changed files with 86 additions and 32 deletions

View File

@@ -219,24 +219,57 @@ class ManageCustomerController extends Controller
}
// public function exportSelectedCustomer(Request $request)
// {
// // dd($request->all());
// try {
// if ($request->has('all_id')) {
// return Excel::download(new customer_export, 'Passport_data.xlsx');
// }
// $ids = $request->selected_id;
// // dd( $ids);
// $fileName = 'selected_customer_data.xlsx';
// return Excel::download(new customer_export_selected($ids), $fileName);
// // dd($ids);
// } catch (\Exception $e) {
// return response()->json(['error' => 'Export failed. Something went wrong.'], 500);
// }
// }
public function exportSelectedCustomer(Request $request)
{
// dd($request->all());
try {
if ($request->has('all_id')) {
return Excel::download(new customer_export, 'Passport_data.xlsx');
}
$ids = $request->selected_id;
// dd( $ids);
// Check if ids is not null or empty
if (empty($ids)) {
return response()->json(['error' => 'No IDs provided for export.'], 400);
}
// Log the ids for debugging purposes
Log::info("Selected IDs for export: " . $ids);
$fileName = 'selected_customer_data.xlsx';
// Additional log before attempting download
Log::info("Attempting to export selected customers to file: " . $fileName);
// Attempt to create and download the Excel file
return Excel::download(new customer_export_selected($ids), $fileName);
} catch (\Exception $e) {
Log::error('Export failed: ' . $e->getMessage());
return response()->json(['error' => 'Export failed. Something went wrong.'], 500);
}
}