laravel - Laravel - 我需要在哪里放置我的 sum()
问题描述
这个变量可以向我显示与sub_account相关的任何发票的数据。
我在发票中有数据,这是我可以正确显示的金额。但我需要显示具有相同 sub_account 的所有金额的总和。如下图所示,每张发票都会出现 2 次问题。
这是我的代码:查看:
@foreach($invoices as $invoice)
@foreach($invoice->subaccount as $sub_accounts)
<tr>
@foreach($sub_accounts->subaccountinvoice as $sub_account)
<td scope="row">{{$sub_account->sum('amount')}}</td>
@endforeach
</tr>
@endforeach
@endforeach
在控制器中:
$invoices = Account::with(['subaccount.subaccountinvoice])->where('id',$id)->get();
谢谢你。
解决方案
只需将 $sum 变量传递给您的视图文件。
return view('yourView')->with(['sumAmount' => $sum]);
然后在视图文件中回显变量 $sumAmount:
{{$sumAmount}}
推荐阅读
- sql-server - DT_NTEXT 到 DT_STR 转换
- excel - Excel ActiveSheet.QueryTables.Add 和非 ASCII 字符
- c# - 领域驱动设计中的 UI 信息
- c++ - omp parallel for:线程无法赋值
- javascript - 按值重新排序对象,但保留键和值
- itext - 使用 PdfWriter 而不是 PdfCopy 复制注释
- r - 具有动态呈现输入的 R Shiny 应用程序的书签状态
- php - 编写 PHP 脚本以选择特殊生成的缩略图 Codeigniter 上的信息
- c++ - 将包含数组的 BSON 文档转换为 JSON,从转换后的 JSON (C++) 中删除数组
- python - Pyinstaller + Tkinter + Mac OS + TCL