Conditional logic with relationships

Help needed with conditional logic / filter:
I have a container with a query loop that shows related posts based on MB Relationship. I will hide the whole container when there is no relation. How to do this?

add_filter( "bricks/element/render", function ($render, $element) { // Get the element CSS classes $classes = !empty($element->attributes["_root"]["class"]) ? $element->attributes["_root"]["class"] : false;
    // Check if the element has the special class "hide-for-subscribers"
    if ($classes && in_array("post-to-dienst", $classes)) {
        return checkRelation('dienst-to-post','to');
    }
    return $render;
},
10,
2

);

function checkRelation($id, $direction)
{
$pages = MB_Relationships_API::get_connected([
“id” => $id,
$direction => get_the_ID(),
]);

$count = count($pages);
if ($count < 1) {
    return 0;
} else {
    return 1;
}

}