category($slug); if ($category === null) { return (new Errors())->notFound(); } $tools = $finder->toolsInCategory($slug); $guides = model(\App\Models\GuideModel::class)->published(50); // guides touching this category's tools $catToolSlugs = array_column($tools, 'slug'); $relatedGuides = array_values(array_filter($guides, static function (array $g) use ($catToolSlugs): bool { $linked = json_decode((string) ($g['tool_slugs'] ?? '[]'), true) ?: []; return count(array_intersect($linked, $catToolSlugs)) > 0; })); $this->seo->title($category['seo_title'] ?: ($category['name'] . ' – Free Online')) ->description($category['seo_description'] ?? (string) $category['tagline']) ->canonical('/' . $category['slug']) ->breadcrumbs([['label' => $category['name']]]) ->webApplication($category['name'], (string) ($category['tagline'] ?? '')) ->faqPage(is_array($category['faqs']) ? $category['faqs'] : []) ->ogImage('/og/' . $category['slug'] . '.png'); $this->trackToolView($category['slug']); return $this->render('category', [ 'category' => $category, 'tools' => $tools, 'featured' => array_slice(array_filter($tools, static fn ($t) => (int) $t['is_featured'] === 1), 0, 4), 'guides' => array_slice($relatedGuides, 0, 3), ]); } }