jeudi 10 novembre 2016

dompdf not loading data vo view Laravel

I'm trying to convert html page to pdf using dompdf wrapper in laravel. If I show the html page, the informations from database are displayed on the page, but when I try to convert that to pdf I have only empty div tags without values from the database.

This is my code for converting pdf:

public function viewUserOrderDetails($id){
        $user = User::find($id);

        $pdf = PDF::loadView('userOrderDetails',['user' => $user]);
        return $pdf->stream("index.pdf");
    }

and the route function:

    Route::post('/userOrderDetails/{id}',[
   'uses' => 'showAllOrders@viewUserOrderDetails',
   'as' => 'orderdetail',
]);

View sample code:

<div class="container">
    <form class="form-horizontal" method="POST">
  <fieldset>
    <div class="col-lg-12 form-group margin50">
      <label class="col-lg-2"  for="Name">User</label>
      <div class="col-lg-4">
          <input type="hidden" name="_token" value="">
          <input type="text" id="name" name="Name" placeholder="" class="form-control name" value="" readonly>
          
      </div>
    </div>

    <div class=" col-lg-12 form-group">
      <label class="col-lg-2" for="ProductType">Orders</label>
      <div class="col-lg-4">
         @foreach($user->orders as $order)
            <input type="text" placeholder="" class="form-control name" value="" readonly>
         @endforeach
      </div>
    </div>
     <div class="col-lg-12 form-group">
      <label class="col-lg-2" for="Manufacturer">Price</label>
      <div class="col-lg-4">
        @foreach($user->orders as $order)
            <input type="text" placeholder="" class="form-control name" value="" readonly>
         @endforeach
      </div>
    </div>
   </div>
    </form>

Also if i try to change $pdf = PDF::loadView('userOrderDetails',['user' => $user]); to this $pdf = PDF::loadView('userOrderDetails',compact('user')); it gives me user not found error

Any ideas?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire