setCache('laravel.sitemap', 3600);// 设置缓存 $categories = Category::where('status', 1)->get(); foreach ($categories as $category) { $url[] = $category->link; } $articles = Article::shown()->get(); foreach ($articles as $article) { $url[] = $article->link; } $staffs = Staff::shown()->get(); foreach ($staffs as $staff) { $url[] = $staff->link; } $dateTime = date('Y-m-d H:i:s'); foreach ($url as $k => $v) { $sitemap->add($v, $dateTime, '1.0', 'daily'); } // 渲染站点地图(options: 'xml' (default), 'html', 'txt', 'ror-rss', 'ror-rdf') return $sitemap->store('xml'); } }