Level 1
Also, I have implemented "Chunk" use Maatwebsite\Excel\Facades\Excel;
public function exportExcelWithChunk() { $Abc_details = Abc::query() ->with(['AbcDetails' => function ($query) { $query->select('id', 'Abc_id', 'description','rate', 'qty', 'per'); }]) ->take(100000) ->get();
if (!empty($Abc_details)) {
foreach ($Abc_details as $Abc_value) {
$grand_total = 0;
foreach($Abc_value->AbcDetails as $Abc_details_data)
{
$line_total = 0;
$row_rate = $Abc_details_data->rate ? $Abc_details_data->rate : 0;
$row_qty = $Abc_details_data->qty ? $Abc_details_data->qty : 0;
$row_per = $Abc_details_data->per ? $Abc_details_data->per : 0;
if (!empty($row_per)) {
$line_total = (((float) $row_rate + (((float) $row_rate * $row_per) / 100)) * $row_qty);
} else {
$line_total = ((float) $row_rate * $row_qty);
}
$grand_total += $line_total;
}
$Abc_arr = [];
$Abc_arr['job_number'] = $Abc_value->job_id ? $Abc_value->job_id : '';
$Abc_arr['doc_no'] = $Abc_value->doc_no ? $Abc_value->doc_no : '';
$Abc_arr['app_no'] = $Abc_value->app_no ? $Abc_value->app_no : '';
$Abc_arr['total_with_per'] = $grand_total;
$Abc_arr['finalised'] = $Abc_value->is_final ? $Abc_value->is_final : '';
$collect_arr[] = $Abc_arr;
}
}
ini_set('max_execution_time',600);
ini_set('memory_limit',"4096");
Excel::create('Report', function ($excel) use ($collect_arr) {
$excel->sheet('report', function ($sheet) use ($collect_arr) {
$sheet->appendRow($this->columns());
$query->chunk(1000, function ($rows) use ($sheet) {
foreach ($rows as $row) {
$sheet->appendRow($this->rows($row));
}
});
});
})->download('xlsx');
}