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

5
  • 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) Commented Jan 4, 2018 at 5: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 :) Commented Jan 4, 2018 at 5:47
  • Just asking is this possible to do? stackoverflow.com/questions/48087633/…, I look around but most people say they can't do it this way Commented Jan 4, 2018 at 5:50
  • hmm, some modification needed to get expected result. Commented Jan 4, 2018 at 6:13
  • You mean the blade part? Something like this?stackoverflow.com/questions/35428288/… Commented Jan 4, 2018 at 6:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.