Filter by Children of Children

I’m trying to filter a collection by the children of the children but without any success. My current page setup:

  • Motive
    • Products
      • Product
      • Product
      • Product

Now I want to filter at the Page “Motive”. The return should be all products that have at least one children with my needed field. Something like this:

$motive = $motive->children()->filter(function ($child) {
  return $child->children()->filterBy('produktart','Acrylglasbild');
});

Currently I’m stuck and no matter what I try I can’t find a solution.

return $child->children()->filterBy('produktart','Acrylglasbild')->count() > 0; // or `isNotEmpty()`

Doesn’t work … here’s more Code:

$motive = $page->children()->listed();

if ( get('produktart') ) {
  $motive = $motive->children()->filter(function ($child) {
    return $child->children()->filterBy('produktart','Acrylglasbild')->count() > 0;
  });
}

Got it :slight_smile:

if ( get('produktart') ) {
  $motive = $motive->filter(function ($child) {
    return $child->children()->filterBy('produktart','Textilspannrahmen')->count() > 0;
  });
}