laravel页面中的总和问题

I have this little problem! I have the page viewcustomers.blade.php in laravel, and I want to sum the results of column cost in the selected ID; I'll try to use foreach but this print the results some times

@foreach($prestamos as $prestamo)
    @if($prestamo->idcliente == $clientes->id)
        <tr>
            <td></td>
            <td>$  {{$prestamo->sum('cantidadpres')}}</td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td>$  {{$prestamo->sum('totalpagar')}}</td>
            <td></td>
            <td></td>
        </tr>
    @endif
@endforeach

And if i use the if without foreach show me an error, then whats is the best way?