Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Sitemap

Laravel Sitemap Laravel Package

spatie/laravel-sitemap

Generate XML sitemaps for Laravel automatically by crawling your site or building them manually. Add URLs, models, lastmod/changefreq/priority, images and alternates, then write to file or disk. Supports sitemap index and large sites.

View on GitHub
Deep Wiki
Context7

spatie/laravel-sitemap helps you generate XML sitemaps for Laravel apps with minimal effort. It can crawl your site to discover URLs automatically, or you can build sitemaps manually with full control over tags like last modification dates.

Combine both approaches by generating a sitemap from a crawl and then adding extra URLs programmatically—ideal for dynamic pages, CMS content, or custom routes.

  • Automatic crawling to discover and include site URLs
  • Manual sitemap building with Sitemap and Url tags
  • Add metadata like lastmod (and more via tag APIs)
  • Mix crawl + manual links in a single sitemap
  • Model-friendly via Sitemapable implementations
Frequently asked questions about Laravel Sitemap
How do I generate a sitemap for my Laravel app without manually listing every URL?
Use the `SitemapGenerator` class to crawl your site automatically. Call `SitemapGenerator::create('https://yourdomain.com')->writeToFile($path)` to discover all URLs dynamically. Configure crawl depth, concurrency, and filters via the generator’s methods to optimize performance.
Can I mix auto-crawled URLs with manually added ones in the same sitemap?
Yes. Start with `SitemapGenerator::create()` to crawl your site, then chain `->getSitemap()->add(Url::create(...))` to append custom URLs. This hybrid approach is ideal for combining static routes with dynamic content like blog posts or CMS pages.
What Laravel versions does spatie/laravel-sitemap support?
The package officially supports Laravel 8.x, 9.x, and 10.x. Check the [GitHub releases](https://github.com/spatie/laravel-sitemap/releases) for version-specific compatibility notes. It leverages Laravel’s service container and filesystem, so updates align with Laravel’s LTS cycles.
How do I add lastmod, changefreq, or priority tags to URLs in a manual sitemap?
Use the `Url` class methods: `setLastModificationDate()`, `setChangeFrequency()`, and `setPriority()`. For example: `Url::create('/page')->setLastModificationDate(Carbon::now())->setChangeFrequency('daily')`. These tags are critical for SEO and can be set per URL or via bulk operations.
Will the crawler work for large sites with thousands of pages? What are the performance risks?
The crawler uses configurable concurrency (default: 10 threads) and depth limits to balance speed and resource usage. For large sites, monitor CPU/memory usage and adjust `->setCrawlDepth()` or `->setMaxCrawlCount()`. Consider running crawls during off-peak hours or via Laravel queues to avoid timeouts.
How do I generate a sitemap index for multiple sitemaps (e.g., paginated or language-specific)?
Use `SitemapGenerator::create()->writeToDisk()` with the `SitemapIndex` class. The package automatically splits sitemaps into chunks (e.g., 50,000 URLs per file) and generates an index.xml. For language-specific sitemaps, create separate generators and merge them into the index.
Can I integrate this with Eloquent models to auto-generate sitemaps for database records?
Yes. Implement the `Sitemapable` interface on your model and define a `getSitemapUrl()` method. The package will automatically include these URLs in the sitemap. For example: `class Post implements Sitemapable { public function getSitemapUrl(): string { return route('posts.show', $this); } }`.
How do I handle JavaScript-rendered content (SPAs, React, Vue) in the sitemap?
Install `spatie/browsershot` to render JS before crawling. Add it to your crawler config: `->useBrowsershot()` and set `execute_javascript = true`. Note this requires Chrome installed on your server and may increase crawl time. For CI/CD, use Docker with Chrome pre-installed.
Is there a way to exclude specific routes or pages from the auto-crawler?
Yes. Use the `shouldCrawl()` method to filter URLs. For example: `->shouldCrawl(function (CrawlRequest $request) { return !Str::startsWith($request->url, '/admin'); })`. You can also exclude URLs via `->ignore()` or `->hasCrawled()` callbacks for dynamic logic.
How do I schedule sitemap regeneration in Laravel (e.g., daily updates)?
Create a custom Artisan command extending `SitemapGenerator` and schedule it in `app/Console/Kernel.php`. Example: `Schedule::command('sitemap:generate')->daily()`. For large sites, use Laravel queues to run the command asynchronously. Test under production load to avoid timeouts during peak traffic.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport