I am trying to return a total using sum() by fetching the "duration" from each user within a $collection
The structure is
USER > CONTRACT_RESULTS > DAYS > DATE > ACTIVITIES > ACTIVITY
I want to query the "type" of activity and pull back the duration that is associated with that activity.
I had it working when it was much less nested using:
$collection->whereIn('activity',['off'])->sum('duration');
But I'm at a loss now since they are so nested and the names of the arrays are dynamic
Here is an example of the structure for 1 user in the $collection:
array:13 [▼
"user_id" => 52
"contract_results" => array:2 [▼
"2019-10-21 - 2019-10-31" => array:10 [▼
"hours_a_week" => "20"
"days" => array:1 [▼
"2019-10-21" => array:2 [▼
"bank_holiday" => "no"
"activities" => array:2 [▼
"10:00 - 22:00" => array:5 [▼
"type" => "driving"
"from" => "10:00"
"to" => "22:00"
"duration" => 720
"night_minutes" => 60
]
"22:00 - 00:00" => array:5 [▼
"type" => "driving"
"from" => "22:00"
"to" => "00:00"
"duration" => 120
"night_minutes" => 120
]
]
]
]
]
"2019-11-01 - 2019-11-10" => array:10 [▼
"hours_a_week" => "10"
"days" => array:1 [▼
"2019-11-01" => array:2 [▼
"bank_holiday" => "yes"
"activities" => array:1 [▼
"10:00 - 22:00" => array:5 [▼
"type" => "availability"
"from" => "10:00"
"to" => "22:00"
"duration" => 720
"night_minutes" => 60
]
]
]
]
]
]
]
I'm new to this so, thank you very much for your input!
activity? I don't seeactivityin your collection.->whereIn('activity', ['off']). I don't seeactivitykey in your collection.