Skip to content

Commit

Permalink
Add utilty methods to filter PageCollection data
Browse files Browse the repository at this point in the history
  • Loading branch information
giuscris committed Sep 21, 2024
1 parent 029f80b commit a5b8f95
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions formwork/src/Pages/PageCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,54 @@ public function search(string $query, int $min = 4): static

return $pageCollection->filterBy('score')->sortBy('score', direction: SORT_DESC);
}

public function withoutChildren(Page $page): static
{
return $this->difference($page->children());
}

public function withoutPageAndChildren(Page $page): static
{
return $this->without($page)->difference($page->children());
}

public function withoutDescendants(Page $page): static
{
return $this->difference($page->descendants());
}

public function withoutPageAndDescendants(Page $page): static
{
return $this->without($page)->difference($page->descendants());
}

public function withoutParent(Page $page): static
{
return $this->without($page->parent());
}

public function withoutPageAndParent(Page $page): static
{
return $this->without($page)->without($page->parent());
}

public function withoutAncestors(Page $page): static
{
return $this->difference($page->ancestors());
}

public function withoutPageAndAncestors(Page $page): static
{
return $this->without($page)->difference($page->ancestors());
}

public function withoutSiblings(Page $page): static
{
return $this->difference($page->siblings());
}

public function withoutPageAndSiblings(Page $page): static
{
return $this->without($page)->difference($page->siblings());
}
}

0 comments on commit a5b8f95

Please sign in to comment.