Aug 4, 2020
22
Level 13
What is the best way to export 1 million records
its took 10 minutes for 1 millions records dowload so how to reduce time for 1 click to downlaod in seconds
public function query()
{
$query = Employee::query()->select($this->getcol())
->leftJoin('employee_bank_details', function($join) {
$join->on('employees.id','=','employee_bank_details.employee_id')
->where('employee_bank_details.pay_type','=',4);
})
->join('company_onboarding_form1 as cf','employees.employer_id','cf.id')
->leftJoin('cities','employees.employee_city_id','cities.id')
->leftJoin('states','employees.employee_state_id','states.id')
->leftJoin('countries','employees.employee_country_id','countries.id')
->leftJoin('cities as ccity','cf.company_city','ccity.id')
->leftJoin('states as cstate','cf.company_state','cstate.id')
->where('employees.employer_id',$this->employer_id);
return $query;
}
controller is here
public function exportToExcel(Request $request, $companyOnboardingId)
{
ini_set('max_execution_time', 300);
$cdt = Carbon ::now();
$export = 'xls';
$fileName = 'company-employees'.$companyOnboardingId.'-'.$cdt->format('YmdHis');
return Excel::download(new CompanyEmployeeExcelExport($companyOnboardingId,$searchArray), $fileName.'.'.$export);
}
Level 122
or,
client said in one click export
client clicks button, your page says thankyou, your file is being prepared and will be emailed to you when it is ready.
There are many on-line services that use this approach. If you have an amazon affiliate account, and ask for a report, they tell you its queued and to come back later when it is ready.
6 likes
Please or to participate in this conversation.