php - 使用 php 传递变量生成 PDF

标签 php html mysql laravel

Web.php 我尝试创建一个空白路由来传递 $contract 变量,以传递变量以使用 dompdf 生成 pdf

Route::get('/blank', function () {
    return view('sell.contractpdf','PdfGenerateController@contract')->name('viewpdf');
});

contractpdf Controller

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();
}

在 View 中:

<h1>f</h1>
@foreach ($contracts as $contract)
<h4>{{$contract->id}}</h4>
@endforeach

错误: undefined variable :合约

最佳答案

这应该是

$contracts

$contracts = Contract::findOrFail(session('contract_id'));
$pdf = PDF::loadView('sell.contractpdf', ['contracts' => $contracts]);

关于php - 使用 php 传递变量生成 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50538270/

相关文章:

php - 从 $_POST 请求(不是从 URL)使用 ParamConverter

PHP cURL header 请求在某些服务器上返回 400

jQuery 手机 : Scroll only the listview

mysql - 使用Spring框架发送POST请求

php - 如何在PHP中更新MySQL表数据而不刷新页面?

php - 使用文本区域修改 MySQL 表字段

php - 使用带有 OpenERP 的网络服务插入订单

html - 用于创建数学方程式的编辑器

php - 是否使用 htmlspecialchars() 进行输入/输出 HTML 清理,用于 MySQL 数据库糟糕的设计?

mysql - 在 MySQL Rails 4 中使用数组