如何在 blade Laravel 中添加两个数字

How to add two numbers in the blade Laravel

我需要添加两个 numbers/amount 显示在我的 blade 视图中,如下图所示

我需要显示为 666.68 / 1000 AUD

这是我的 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');
}

请告诉我如何进行这项工作

这个有效

<td>
    {{ $team->competitionPayments->sum('amount') }}
    /
    @foreach ($team->competitions as $total)
    {{ $total->pivot->total_fee .' AUD'}}
    @endforeach
</td>

这里 competitionPayments 是一个集合,因此您可以像

一样在其上应用 sum() 函数
<td>
  {{ $payment->competitionPayments->sum('amount') }}
<br>

ref link https://laravel.com/docs/8.x/collections#method-sum