我需要将刀片视图中显示的两个数字/金额相加,如下图所示

我需要显示为666.68 / 1000澳元
这是我的blade代码
<td>
@foreach ($team->competitionPayments as $payment)
{{ $payment->amount }}
@endforeach
<br>
{{ $team->competitionPayments }}
/
@foreach ($team->competitions as $total)
{{ $total->pivot->total_fee .' AUD'}}
@endforeach
</td>下面是我的controller函数
public function detailedRegistrations($competition)
{
$competitions = $this->competitionsRepo->findOrFail($competition);
$teams = $competitions->teams()->get();
$payments = $competitions->payments()->get();
return view('competitions.detailed-registrations',
[
'teams'=>$teams,
'payments'=>$payments,
'competitions'=>$competitions,
]
);
}下面是Team model中的competitionPayments关系
public function competitionPayments()
{
return $this->hasMany(CompetitionPayment::class, 'team_id');
}请给我一个如何工作的想法
发布于 2020-12-09 12:43:05
这里的competitionPayments是一个集合,因此您可以对其应用sum()函数,如下所示
<td>
{{ $payment->competitionPayments->sum('amount') }}
<br>发布于 2020-12-09 12:42:44
这是可行的
<td>
{{ $team->competitionPayments->sum('amount') }}
/
@foreach ($team->competitions as $total)
{{ $total->pivot->total_fee .' AUD'}}
@endforeach
</td>https://stackoverflow.com/questions/65210573
复制相似问题