Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Hamelraj's avatar

Maatwebsite Excel export with multiple formarray

im trying to pass multiple arrays export excel but one array duplicate on other array how to solve this

 $jobs = HvAccountJob::whereBetween('date', [$start, $end])->where('company_id',1)->get();
                $data = array('NO','COMPANY NAME','JOB NO','INVOICE NO','VESSEL NAME / VESSEL DATE','AMOUNT');
                $sheet->fromArray(array($data),null,'A6',false,false);
                $x = 0;
                foreach($jobs  as $index =>$row){
                    $data=array($index+1,$row->company->name,$row->job_no,$row->invoice_no,$row->customer_name,'€'.$row->amount);
                    $sheet->fromArray(array($data),null,'A6',false,false);
                $x++;
                }

$jobs1 = HvAccountJob::whereBetween('date', [$start, $end])->where('company_id','>',1)->get();
                $d = array('NO','COMPANY NAME','JOB NO','INVOICE NO','VESSEL NAME / VESSEL DATE','AMOUNT');
                $sheet->fromArray(array($d),null,'A13',false,false);
                foreach($jobs1  as $index =>$row){
                    $d=array($index+1,$row->company->name,$row->job_no,$row->invoice_no,$row->customer_name,$row->amount);
                    $sheet->fromArray(array($d),null,'A13',false,false);

                }

http://imgur.com/a/9Pxij

0 likes
3 replies
jimmck's avatar

You have 2 queries $job and $job1. Now only your know your data, but why 2. In SQL this would be a single query with a group by.

Hamelraj's avatar

can any one help this ????????????????????????????????????????

Please or to participate in this conversation.