van1310
1 month ago
622
22
Laravel

What is the best way to export 1 million records

Posted 1 month ago by van1310

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);        
    }

Please sign in or create an account to participate in this conversation.