$pages->filter($callback)

Filters the collection with a custom filter callback

  • $callback (func)
    The callback function
  • return ($pages)

Example

// fetch children with a title starting with 'Project'
$items = $page->children()->filter(function($child) {
  return str::startsWith($child->title(), 'Project');
});

// fetch children with more than 2 images
$items = $page->children()->filter(function($child) {
  return $child->images()->count() > 2;
});

// fetch visible children which have visible children
$items = $page->children()->visible()->filter(function($child) {
  return $child->hasVisibleChildren();
});

//fetch children in the current language only
$items = $page->children()->visible()->filter(function($child) {
  return $child->content(site()->language()->code())->exists();
});