Reputation: 703
hi guys, im trying to use barryvdh/laravel-dompdf, everything works fine except i cant load my data to the view to dynamically produce content, i keep getting 'Undefined variable: data'
here is my code:
$data =[
'fname'=>Input::get('efname'),
'lname'=>Input::get('elname'),
'dob'=>Input::get('edob'),
'reg_date'=>date('Y-m-d'),
'email'=>Input::get('eemailaddrs'),
'gender'=>Input::get('gender'),
'mobile'=>Input::get('emobile'),
'p_addrss'=>Input::get('epaddress'),
'c_addrss'=>Input::get('ecaddress'),
'quals'=>Input::get('quali'),
'pdfname'=>$pdfname,
'empId'=>Input::get('employeeId'),
];
return PDF::loadView('employee/generatepdf',$data)
->save(public_path().'/pdfs/'.$pdfname.'.pdf');
its going to pdf template page..But cant get the array values.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<img align="center" src="{{public_path()}}/assets/img/logo.png">
<table align="center" style="width:100%;margin-top:25px;">
<tr>
<td style="width:50%">Registration ID</td>
<td style="width:50%">:{{$data['empId']}}</td>
</tr>
<tr>
<td style="width:50%">Name</td>
<td style="width:50%">:{{$data['fname']}} {{$data['lname']}}</td>
</tr>
</table>
</body>
</html>
also not taking css rules into pdf file.
How can i solve this issue...?
Thanks
Upvotes: 0
Views: 4388
Reputation: 1
You need to pass $data
variable using compact()
function
return PDF::loadView('employee/generatepdf',compact('data'))
->save(public_path().'/pdfs/'.$pdfname.'.pdf');
Upvotes: 0
Reputation: 381
You can check if array contain data or not by :
$data =[
'fname'=>Input::get('efname'),
'lname'=>Input::get('elname'),
'dob'=>Input::get('edob'),
'reg_date'=>date('Y-m-d'),
'email'=>Input::get('eemailaddrs'),
'gender'=>Input::get('gender'),
'mobile'=>Input::get('emobile'),
'p_addrss'=>Input::get('epaddress'),
'c_addrss'=>Input::get('ecaddress'),
'quals'=>Input::get('quali'),
'pdfname'=>$pdfname,
'empId'=>Input::get('employeeId'),
];
dd($data);
return PDF::loadView('employee/generatepdf',$data)->save(public_path().'/pdfs/'.$pdfname.'.pdf');
just try it and you will find if your array contain data or not
Upvotes: 1
Reputation: 365
Try like that, Use an array as second argument for the view.
return PDF::loadView('employee/generatepdf',array('data'=>$data));
Upvotes: 0