после цикла почему то пустой массив,но если задампить итерацию то результат есть,но за циклом $types пустой
$objects = Object::where(['status' => 1])->get()->sortBy('sort');
foreach ($objects as $object) {
$types = [];
foreach (ApartmentType::all() as $type) {
$apartmentsObject = $object->load(['porches.floors.apartments' => function($q) use ($object,$type, $types){
array_push($types,['count'=>$q->where('type_id',$type->id)->count(),'value'=>$type->title]);
}]);
}
var_dump($types); exit;
// $object->apartments = $types;
}