From a5b8f951d88f74afc40d536cec062d1d892c9081 Mon Sep 17 00:00:00 2001 From: Giuseppe Criscione <18699708+giuscris@users.noreply.github.com> Date: Sat, 21 Sep 2024 15:01:35 +0200 Subject: [PATCH] Add utilty methods to filter `PageCollection` data --- formwork/src/Pages/PageCollection.php | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/formwork/src/Pages/PageCollection.php b/formwork/src/Pages/PageCollection.php index 34c9db15..fe773b1e 100644 --- a/formwork/src/Pages/PageCollection.php +++ b/formwork/src/Pages/PageCollection.php @@ -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()); + } }