Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing variable from DOMPDF controller to view

Tags:

laravel

dompdf

I want create a DOMPDF with laravel, and I must passing my variable to view. I've been try passing variable like below, but it still not working yet.

here my Laravel Controller

 public function pdf(Request $request, $id){
    $salesorder = $this->show($id)->salesorder;
    $detailservice = $this->show($id)->detailservice;
    $detailemployee = $this->show($id)->detailemployee;

    $data = [$salesorder, $detailemployee, $detailservice];

    $pdf = PDF::loadView('summary.invoice', $data);
    return $pdf->download('invoice.pdf');
}

the error on my view is :

Undefined variable: salesorder

How to passing some variable from Laravel controller to DOMPDF ?

PS : dd($data) result is correctly

like image 702
rafitio Avatar asked Dec 23 '22 22:12

rafitio


2 Answers

You have to pass the data as below

$data = [
    'salesorder'     => $salesorder,
    'detailemployee' => $detailemployee,
    'detailservice'  => $detailservice
];

or try using compact

$data = compact('salesorder', 'detailemployee', 'detailservice');
like image 160
Saumini Navaratnam Avatar answered Dec 28 '22 09:12

Saumini Navaratnam


You may try this following

public function pdf(Request $request, $id){
    $salesorder = $this->show($id)->salesorder;
    $detailservice = $this->show($id)->detailservice;
    $detailemployee = $this->show($id)->detailemployee;

    $pdf = PDF::loadView('summary.invoice', array('salesorder' => $salesorder,'detailemployee'=>$detailemployee,'detailservice'=>$detailservice));
    return $pdf->download('invoice.pdf');
}
like image 31
Rojith Randula Peiris Avatar answered Dec 28 '22 11:12

Rojith Randula Peiris