php - 如何通过压缩发送收藏到pdf功能
问题描述
我正在尝试为每个紧凑型发送一个数组,但是在查看它时会引发错误。
销售控制器.php
public function generarRecibo($id)
{
$sales = Sale::with('client', 'products')->where('id', '=', $id)->get();
$pdf = PDF::loadView('pdf.sales-recibo', compact(['sales']) );
return $pdf->stream('Recibo N° '.$id.'.pdf');
}
销售-recibo.blade.php
<table class="table">
<tbody>
@foreach ($sales->products as $product)
<tr>
<td style="border: 0px;" colspan="3">{{ $product->name }}</td>
</tr>
<tr>
<td style="border: 0px;">
<ul>
<li>{{ $product->quantity }} X ${{ number_format($product->price, 0,',','.') }}</li>
</ul>
</td>
<td style="border: 0px;" width="150px"></td>
<td style="border: 0px;" width="150px">${{ number_format($product->price, 0,',','.') }}</td>
</tr>
@endforeach
</tbody>
</table>
解决方案
代替get()
使用find()
方法
$sales = Sale::with('client', 'products')->find($id);
你也有紧凑的问题
$pdf = PDF::loadView('pdf.sales-recibo', compact('sales') );
推荐阅读
- reactjs - 如何解决减速器内部的解析错误问题?
- java - 通过 JCA 适配器侦听的 EJB MDB 在启动时失败
- c++ - getLine() 返回换行符并且没有数据
- r - 社交网络分析和组件大小 - igraph R SNA
- python-3.x - ValueError:检查目标时出错:预期dense_2的形状为(1,)但得到的数组形状为(500,)[情绪分析]
- wordpress - WP REST API 返回 HTML 而不是 JSON
- javascript - 格式化单元格文本颜色
- python-3.x - 关闭连接时出现socket错误,如何解决?
- java - 从 dockerfile 构建 docker 映像,无法让 java 正确运行,但可以从映像运行 java 作为 docker run 命令中的命令行参数
- extjs - 如何防止在网格面板中单击单元格时自动水平滚动