How to use multiple sitemaps with sitemap index (with store() method)
Route::get('sitemap-store', function()
{
// create sitemap
$sitemap_posts = App::make("sitemap");
// add items
$posts = DB::table('posts')->orderBy('created_at', 'desc')->get();
foreach ($posts as $post)
{
$sitemap_posts->add($post->slug, $post->modified, $post->priority, $post->freq);
}
// create file sitemap-posts.xml in your public folder (format, filename)
$sitemap_posts->store('xml','sitemap-posts');
// create sitemap
$sitemap_tags = App::make("sitemap");
// add items
$tags = DB::table('tags')->get();
foreach ($tags as $tag)
{
$sitemap-tags->add($tag->slug, null, '0.5', 'weekly');
}
// create file sitemap-tags.xml in your public folder (format, filename)
$sitemap_tags->store('xml','sitemap-tags');
// create sitemap index
$sitemap = App::make ("sitemap");
// add sitemaps (loc, lastmod (optional))
$sitemap->addSitemap(URL::to('sitemap-posts'));
$sitemap->addSitemap(URL::to('sitemap-tags'));
// create file sitemap.xml in your public folder (format, filename)
$sitemap->store('sitemapindex','sitemap');
});
Entrepreneur, tech enthusiast and Full-stack developer, Constantly learning and experiencing new things.