I'm wondering how I can sum the attributes of a multiply-nested relation in Laravel. I'm aware that Laravel has some cool sum functions as shown here, but wondering how to take that one level deeper.
My models are set up as follows:
Projects have many tasks.
Tasks have many logs.
Logs have an attribute "duration."
I've queried projects and are iterating through projects in an html table. I want to display the sum of the log durations. I was thinking maybe I could do something like:
$project->tasks->logs->sum('duration')
But that doesn't do it. Is this possible to do with a single, elegant line like this, or am I going to have to set up a loop and sum "manually"?