title: laravel generate PDF from blade
body: <p>I am trying to download my page in pdf format and I have been following this tutorial step by step to do it. I tried using a sample data to do it and it work but when I try to use my own data it keep giving me undefined $data3, $object, ..</p>
  
  <p>But I have already defined them already in my controller already:</p>
  
  <p>testController</p>
  
  <pre><code>     public function getTestdata($id){
             $user = PersonalInfo::find($id);
            $object = PersonalInfo::where('id',$id)-&gt;get();
          $object1 = AdditionalInformation::where('user_id',$id)-&gt;get(); 
           $data3=UserImage::where('user_id',$id)-&gt;get();
       return view('test',compact('id','object','object1','user','data3'));
   }
  </code></pre>
  
  <p>test.blade.php</p>
  
  <pre><code>&lt;a href="{{  url('/pdf')  }}"&gt;Download PDF&lt;/a&gt;
  ...
  &lt;th&gt;
        @foreach($data3 as $currentUser)
        &lt;img src="{{ url('images/' . $currentUser-&gt;name ) }}"&gt;
        @endforeach
   &lt;/th&gt;
  ...
    @php
      $userFamily = $user-&gt;userFamily;
    @endphp
      &lt;tr&gt;
      &lt;td&gt;&lt;b&gt;FAMILY Members&lt;/b&gt;&lt;/td&gt;
        &lt;td&gt;
      @foreach($userFamily as $val)
  
      @if($val["meta_key"] == "relationshiplist")
      {{  $val["meta_value"]  }}  |
      @endif
          @endforeach
      &lt;/td&gt;
  </code></pre>
  
  <p>DownloadPDFController:</p>
  
  <pre><code>public function fun_pdf(){
      $pdf = PDF::loadView('test'); //load view page
      return $pdf-&gt;download('test.pdf'); // download pdf file
  }
  </code></pre>
  
  <p>Route:</p>
  
  <pre><code>Route::get('/pdf', 'pdfDownloadController@fun_pdf');
  Route::get('/user/showtest/{id}/test1', 'testController@getTestData')-&gt;name('template');
  </code></pre>
  
  <p>I also tried following this website to do but it does't seem to work as well, instead it gave me undefined $id. <a href="http://itsolutionstuff.com/post/laravel-5-generate-pdf-from-html-view-file-and-download-using-dompdfexample.html" rel="nofollow noreferrer">http://itsolutionstuff.com/post/laravel-5-generate-pdf-from-html-view-file-and-download-using-dompdfexample.html</a></p>
  
  <p>If possible could you guys guide me on how to generate the PDF file</p>