with('oCategory.oParent')->orderByDesc('created_at')->orderByDesc('id')->get(); $latest = app(ArticlesService::class)->getLatestFreeNodeSlug(); $home = $latest ? $articles->firstWhere('sSlug',$latest) : null; $entries = $home ? [['url'=>Seo::url(),'modified'=>Seo::modified($home)]] : []; foreach (Categories::where('iStatus',1)->with('oParent')->orderBy('id')->get() as $category) { if ($category->iParentId && (!$category->oParent || !$category->oParent->iStatus)) continue; $members = $articles->filter(fn($a)=>$a->iCategoryId === $category->id || ($category->iShowChildren && $a->oCategory->iParentId === $category->id)); if ($members->isNotEmpty()) $entries[] = ['url'=>Seo::url(Seo::categoryPath($category)),'modified'=>null]; } foreach ($articles->filter(fn($a)=>Seo::indexable($a)) as $a) $entries[] = ['url'=>Seo::articleUrl($a),'modified'=>Seo::modified($a)]; return response()->view('sitemap',['entries'=>$entries])->header('Content-Type','application/xml; charset=UTF-8'); } }