我正在尝试使用laravel中的dompdf包装器将html页面转换为pdf。如果我显示html页面,数据库中的信息会显示在页面上,但是当我尝试将其转换为pdf时,我只有空的div标签而没有来自数据库的值。
这是我转换pdf的代码:
public function viewUserOrderDetails($id){
$user = User::find($id);
$pdf = PDF::loadView('userOrderDetails',['user' => $user]);
return $pdf->stream("index.pdf");
}
和路线功能:
Route::post('/userOrderDetails/{id}',[
'uses' => 'showAllOrders@viewUserOrderDetails',
'as' => 'orderdetail',
]);
查看示例代码:
<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="{{ csrf_token() }}">
<input type="text" id="name" name="Name" placeholder="" class="form-control name" value="{{ $user->name }}" readonly>
{{ csrf_field() }}
</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="{{ $order->order_name }}" 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="{{ $order->cena }}" readonly>
@endforeach
</div>
</div>
</div>
</form>
此外,如果我尝试将$pdf = PDF::loadView('userOrderDetails',['user' => $user]);
更改为此
$pdf = PDF::loadView('userOrderDetails',compact('user'));
它给了我user not found error
有什么想法吗?