This is a Laravel 8, 9, 10 and 11 only fork of Laravelium/laravel-sitemap. The original repository has been abandoned.
PHP ^8.0
is required.
If laravelium/sitemap
is already part of the project:
composer remove laravelium/sitemap
Then run:
composer require ultrono/laravel-sitemap
php artisan vendor:publish --provider="Ultrono\Sitemap\SitemapServiceProvider"
Route::get('mysitemap', function() {
$sitemap = resolve("sitemap");
$sitemap->add(URL::to(), '2012-08-25T20:10:00+02:00', '1.0', 'daily');
$sitemap->add(URL::to('page'), '2012-08-26T12:30:00+02:00', '0.9', 'monthly');
$posts = DB::table('posts')->orderBy('created_at', 'desc')->get();
foreach ($posts as $post) {
$sitemap->add($post->slug, $post->modified, $post->priority, $post->freq);
}
// generate (format, filename)
// sitemap.xml is stored within the public folder
$sitemap->store('xml', 'sitemap');
});
- How to generate dynamic sitemap (with optional caching)
- How to generate BIG sitemaps (with more than 1M items)
- How to generate sitemap to a file
- How to use multiple sitemaps with sitemap index
and more in the Wiki.