In the image below we see a typical example of Collection in Laravel. We can see in relations another collection.
How do I access this in View?
I'm doing so on the Controller:
$users = User::with(['logs' => function($q) use ($startAt, $endAt){
$q->whereDate('created_at', '>=', $startAt->format('Y-m-d H:i:s'));
$q->whereDate('created_at', '<=', $endAt->format('Y-m-d H:i:s'));
}]);
I know that in View I can make one:
@foreach($users as $user)
@endforeach
The question is how can I get the Collection 'Logs' inside Foreach for that user that is passing there.
GroupBy and Filter
$videoList = $user['logs']->filter(function($q){
return $q->content->type == 'video';
})->groupBy('content_id');