Want better Google rankings? Generating a clean and up-to-date sitemap is one of the easiest wins for your websiteβs SEO. With this package, your sitemap is always synced with your route and content structure, no manual edits needed. Search engines like Google and Bing use your sitemap to crawl your site smarter and faster, which means your new pages and updates show up in search results sooner. Whether you're running a blog, webshop, or custom platform, an automated sitemap gives you an edge in visibility and indexing accuracy.
Lightweight. Extensible. Template-driven.
- π Automatic sitemap generation from named routes via
->sitemap()
- π§© Advanced route templates via
->sitemapUsing(MyTemplate::class)
- π§ Built-in
Template
abstract with helpers likeurlsFromModel()
- βοΈ Configure
lastmod
,priority
,changefreq
per URL - πΎ Save or serve sitemaps via disk or route
- π§ͺ Fully tested with Pest and Laravel Testbench
- π¦ Optional meta-tag injection in
<head>
- β Laravel 10, 11, and 12 support
This package is quick to set up and works out-of-the-box with Laravel 10, 11, and 12. After installing via Composer, you can instantly publish the sitemap route and configuration using a single command. The php artisan sitemap:install
command automatically adds a new sitemap.php
route file and wires it into your existing web.php, so your sitemap is live without extra setup. Itβs the easiest way to boost your SEO visibility with structured sitemap data.
composer require veiliglanceren/laravel-seo-sitemap
Publish the route & config:
php artisan sitemap:install
php artisan vendor:publish --tag=sitemap-config
This package offers a clean and developer-friendly approach to sitemap generation in Laravel. Whether you're working with static pages or dynamic content from models, adding them to your sitemap is seamless. Use a single macro call for simple routes, or create powerful model-driven templates using the built-in abstract Template
class to handle large, dynamic datasets. With just a few lines of code, your entire site structure becomes SEO-friendly and ready for search engine indexing.
The Route
is getting implemented by calling the ->sitemap()
Macro.
use VeiligLanceren\LaravelSeoSitemap\Support\Enums\ChangeFrequency;
Route::get('/contact', ContactController::class)
->name('contact')
->sitemap()
->changefreq(ChangeFrequency::WEEKLY)
->priority('0.8');
The package includes expressive route macros that make it easy to configure sitemap settings directly in your routes/web.php
file.
Marks the route as sitemap-included.
Route::get('/about', AboutController::class)
->name('about')
->sitemap();
Defines how frequently the content at the URL is likely to change.
use VeiligLanceren\LaravelSeoSitemap\Support\Enums\ChangeFrequency;
Route::get('/blog', BlogController::class)
->name('blog.index')
->sitemap()
->changefreq(ChangeFrequency::WEEKLY);
Sets the priority of this URL relative to other URLs on your site.
Route::get('/contact', ContactController::class)
->name('contact')
->sitemap()
->priority('0.8');
π‘ These macros can be chained for fluent configuration and better readability.
Use a custom Template
that extends the abstract Template
class:
// routes/web.php
Route::get('/blog/{slug}', BlogController::class)
->name('blog.show')
->sitemapUsing(\App\Sitemap\Templates\PostTemplate::class);
Read more about all of the helper functions: template helper functions
namespace App\Sitemap\Templates;
use App\Models\Post;
use Illuminate\Routing\Route;
use VeiligLanceren\LaravelSeoSitemap\Sitemap\Item\Url;
use VeiligLanceren\LaravelSeoSitemap\Sitemap\Template;
class PostTemplate extends Template
{
public function generate(Route $route): iterable
{
yield from $this->urlsFromModel(Post::class, $route, function (Post $post, Route $route) {
return Url::make(route($route->getName(), ['slug' => $post->slug]))
->lastmod($post->updated_at)
->priority(0.6);
});
}
}
Generate an index that references multiple sitemap files (e.g. per section):
use VeiligLanceren\LaravelSeoSitemap\Sitemap\SitemapIndex;
$sitemapIndex = SitemapIndex::make([
'https://example.com/sitemap-pages.xml',
'https://example.com/sitemap-posts.xml',
]);
You can dynamically add entries and pretty-print XML:
$sitemapIndex->add('https://example.com/sitemap-products.xml');
Storage::disk('public')->put('sitemap.xml', $sitemapIndex->toXml());
π Read more: docs/sitemapindex.md
use VeiligLanceren\LaravelSeoSitemap\Facades\Sitemap;
Sitemap::fromRoutes()
->getSitemap()
->save('sitemap.xml', 'public');
Or use the CLI:
php artisan sitemap:generate
use VeiligLanceren\LaravelSeoSitemap\Sitemap\Item\Url;
use VeiligLanceren\LaravelSeoSitemap\Sitemap\Item\Image;
$url = Url::make('https://example.com')
->addImage(Image::make('https://example.com/image1.jpg')->title('Hero 1'))
->addImage(Image::make('https://example.com/image2.jpg')->title('Hero 2'));
<head>
{!! Sitemap::meta() !!}
</head>
Outputs:
<link rel="sitemap" type="application/xml" title="Sitemap" href="/sitemap.xml" />
vendor/bin/pest
SQLite must be enabled for in-memory testing.
MIT Β© VeiligLanceren.nl