$columns = [
'S. NO',
'IFSC CODE',
'BANK NAME',
'BRANCH NAME',
'BRANCH ADDRESS',
'BRANCH PINCODE',
'BRANCH AREA 1',
'BRANCH AREA 2',
'BRANCH STATE',
'CREATED AT',
'UPDATED AT',
];
// create csv
return response()->streamDownload(function () use ($columns) {
$file = fopen('php://output', 'w+');
fputxlsx($file, $columns);
$data = IfscMaster::select(
'id',
'ifs_code',
'bank_name',
'branch_name',
'branch_address',
'branch_pincode',
'branch_area1',
'branch_area2',
'branch_state',
'created_at',
'updated_at',
)
->orderBy('id', 'desc');
$data = $data->cursor()
->each(function ($data) use ($file) {
$data = $data->toArray();
fputcsv($file, $data);
});
fclose($file);
}, 'AllUsersCSV' . date('d-m-Y') . '.xlsx');
die;