0

I am trying to show a view through excel and for some reason the data is not being shown, can someone tell me what I am doing wrong here?

Here is the code:

$data2 = PositionApplied::select('PermRelief')->where('PermRelief','=','Permanent')->get();
$data1 = PositionApplied::select('PermRelief')->where('PermRelief','=','Relief')->get();
$perm = count($data2);
$relief = count($data1);
$total = $perm + $relief;
$percent1 = $perm/$total;
$permPercent = round((float)$percent1 * 100 ) . '%';

$percent2 = $relief/$total;
$reliefPercent = round((float)$percent2 * 100 ) . '%';

$percent3 = $total/$total;
$totalpercent = round((float)$percent3 * 100 ) . '%';

return Excel::create('Report', function($excel) use ($data,$perm,$relief,$permPercent,$reliefPercent,$totalpercent,$total) {
    $excel->sheet('Applicant', function($sheet) use ($data)
    {
        $sheet->fromArray($data);
        //$sheet->loadview('excelInfo');
    });
    $excel->sheet('Applicant1', function($sheet) use ($perm,$relif,$permPercent,$reliefPercent,$totalpercent,$total)
    {

        $sheet->loadview('excelInfo')->with('perm')->with('relief')->with('permPercent')->with('permPercent')->with('reliefPercent')->with('totalpercent')->with('total');

    });
  })->download($type);
}

All the data that I used are showing up in the excel why is that? I did a dd on it and return me their value in the controller, but why it is not showing in the excel after downloading? Can someone help me here? Thanks a lot

VinoCoder
  • 1,133
  • 5
  • 22
  • 45
Dkna
  • 409
  • 3
  • 15
  • 37
  • you have not pass the variables of data in the view at all the right syntax is. `$sheet->loadview('excelInfo')->with('perm',$perm)->with('relief',$relief)` – Dhaval Purohit Jan 04 '18 at 05:42
  • Ohh that was the problem, I saw some people doing that and I thought it was just assigning some raw data into it so I didn't use it, didn't know the real purpose was like this. Thank you so much for your help :) – Dkna Jan 04 '18 at 05:47
  • Just asking is this possible to do? https://stackoverflow.com/questions/48087633/positioning-loadview-data-in-laravel-excel, I look around but most people say they can't do it this way – Dkna Jan 04 '18 at 05:50
  • hmm, some modification needed to get expected result. – Dhaval Purohit Jan 04 '18 at 06:13
  • You mean the blade part? Something like this?https://stackoverflow.com/questions/35428288/laravel-excel-how-to-load-a-view-to-specific-row-or-cell – Dkna Jan 04 '18 at 06:19

0 Answers0