0

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

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

Try like that, Use an array as second argument for the view.

return PDF::loadView('employee/generatepdf',array('data'=>$data));

Comments

0

You need to pass $data variable using compact() function

return PDF::loadView('employee/generatepdf',compact('data'))
    ->save(public_path().'/pdfs/'.$pdfname.'.pdf');

Comments

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.