Web.php 我尝试使用空白路径传递$ contract变量以传递变量以使用dompdf生成pdf
Route::get('/blank', function () {
return view('sell.contractpdf','PdfGenerateController@contract')->name('viewpdf');
});
contractpdf控制器
public function pdfview(Request $request)
{
$contract = Contract::findOrFail(session('contract_id'));
$pdf = App::make('dompdf.wrapper');
$pdf = PDF::loadView('sell.contractpdf', $contract);
return $pdf->stream();
}
在视图中
<h1>f</h1>
@foreach ($contracts as $contract)
<h4>{{$contract->id}}</h4>
@endforeach
错误: 未定义的变量:合同
答案 0 :(得分:0)
这应该是
$合同<强>取值强>
$contracts = Contract::findOrFail(session('contract_id'));
$pdf = PDF::loadView('sell.contractpdf', ['contracts' => $contracts]);