The models I have are : **Invoice** - **Credit\_note** - **Payment**

* An Invoice hasMany Credit\_notes
* Each Credit\_note has a single Payment
* A Payment is not directly related to a Credit\_note

What I need to do is to calculate **the sum of the Payments(amount) of the Credit\_notes of an Invoice**.

With the relations I currently have in place, I can load all the Credit\_notes (with their Payments) of an Invoice.

```
Credit_note::with(['payment'])->where('invoice_id', $i->id)

```

I could then sum the amounts by hand... but, is there a way to directly return the sum with the query ?

I tried to add a `->sum('payment.amount')` or something similar, with no luck.

Thanks.