You can add a scope to get those values
public function scopeApartmentsCount($query)
{
return $query->withCount('apartments');
}
and for the active
public function scopeAvailableCount($query)
{
return $query->with(['apartments' => function($q) { return $q->where('active', true); }]);
}
This should do it.