From e30692b3529dcf5b7ddaba84bf2b3d8fa01bea86 Mon Sep 17 00:00:00 2001 From: Michael Aerni Date: Wed, 29 May 2024 21:30:32 +0200 Subject: [PATCH] Save resources by targeting specific type --- src/Sitemap/SitemapRepository.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Sitemap/SitemapRepository.php b/src/Sitemap/SitemapRepository.php index 009da8ba..a06f359d 100644 --- a/src/Sitemap/SitemapRepository.php +++ b/src/Sitemap/SitemapRepository.php @@ -2,10 +2,11 @@ namespace Aerni\AdvancedSeo\Sitemap; +use Illuminate\Support\Str; use Illuminate\Support\Collection; -use Statamic\Facades\Collection as CollectionApi; -use Statamic\Facades\Taxonomy as TaxonomyApi; use Aerni\AdvancedSeo\Contracts\Sitemap; +use Statamic\Facades\Taxonomy as TaxonomyApi; +use Statamic\Facades\Collection as CollectionApi; class SitemapRepository { @@ -38,7 +39,9 @@ public function all(): Collection public function find(string $id): ?Sitemap { - return $this->all()->first(fn ($sitemap) => $id === $sitemap->id()); + $method = Str::before($id, '::') . 'Sitemaps'; + + return $this->$method()->first(fn ($sitemap) => $id === $sitemap->id()); } public function collectionSitemaps(): Collection