nikocraft
1061
4
Laravel

whats the best way to generate sitemap in Laravel

Posted 2 years ago by nikocraft

Hi

I need to generate sitemap for website that potentially could have very large number of user contributed content. I've read this tutorial: https://laravel-news.com/2016/09/laravel-sitemap/ It gives example like this:

public function podcasts()
{
    $podcast = Podcast::active()->orderBy('updated_at', 'desc')->get();
    return response()->view('sitemap.podcasts', [
        'podcasts' => $podcast,
    ])->header('Content-Type', 'text/xml');
}

What I don't like is that it's getting all the podcasts from the database at once, if you have 1 million records, that will slow down everyting and this function will be called each time a webspider requests a sitemap.

Is there a smarter way to do this? For example just update sitemap when new record is added, but how would this be accomplished, any ideas?

Please sign in or create an account to participate in this conversation.