Laravel Sitemap

Generate XML sitemaps for a Laravel app by crawling it or building URLs manually

Library
Composer
v8.2.0
2,618stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
75/100Good
Development Activity60
Maintenance64
Community76
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
75/100Good
Architecture76
Code Quality80
Innovation62
Learning Curve80

Laravel Sitemap, from Spatie, generates standards-compliant XML sitemaps for Laravel applications without requiring every URL to be registered by hand. Its SitemapGenerator crawls a site’s pages (built on Spatie’s own spatie/crawler package) and automatically discovers URLs to include, while the lower-level Sitemap/SitemapIndex/Tags classes let developers construct a sitemap (or a sitemap index spanning multiple sitemap files) programmatically when full control over which URLs are listed is preferred.

Generated sitemaps can be written directly to a file or returned as a response, and support the standard <url> tag fields search engines read (lastmod, changefreq, priority, alternate-language links, images), making it a drop-in way to keep a Laravel site’s sitemap accurate as pages are added or removed.

What You Get

  • SitemapGenerator::create($url) to crawl a site and automatically build a sitemap from discovered pages
  • Manual Sitemap/SitemapIndex builder classes for full control over which URLs, priorities, and change frequencies are included
  • Support for sitemap indexes spanning multiple sitemap files for large sites
  • Per-URL metadata tags (lastmod, changefreq, priority, alternate-language hreflang links, images) matching the sitemap XML protocol
  • Direct writeToFile() output or returning the sitemap as an HTTP response from a Laravel route

Common Use Cases

  • Auto-generating an up-to-date XML sitemap for a Laravel site by crawling it on a scheduled job
  • Building a manually curated sitemap for a site where only certain routes (not every crawlable page) should be listed
  • Splitting a large site’s sitemap across multiple files via a sitemap index for search engine crawl-budget reasons
  • Including alternate-language (hreflang) links per URL for multilingual Laravel sites

Under The Hood

Architecture SitemapGenerator.php orchestrates crawling by configuring and running a Crawler/ wrapper around Spatie’s separate spatie/crawler package, collecting discovered URLs into a Sitemap.php instance; Sitemap.php and SitemapIndex.php both implement a shared Contracts/ interface for adding Tags\Url entries and rendering them to XML via Blade view templates under resources/. SitemapServiceProvider.php registers the package’s config (crawl profile, execute-in-parallel settings, HTTP client options) with the host Laravel application using spatie/laravel-package-tools. Each Tags\Url entry carries the metadata fields (lastmod, priority, changefreq, alternates, images) that get serialized into the final sitemap XML. Tech Stack Requires PHP 8.4+ and Laravel 12/13 (illuminate/support), builds on spatie/crawler ^9.0 for the crawling engine and nesbot/carbon for date handling, with spatie/laravel-package-tools handling standard Spatie-package service-provider boilerplate. Code Quality Tests (SitemapGeneratorTest, SitemapTest, SitemapIndexTest, plus Crawler and Tags subdirectories) run under Pest with snapshot testing (spatie/pest-plugin-snapshots, tests/__snapshots__) to catch unintended changes in generated XML output, and the package runs Larastan/PHPStan with a committed baseline for static analysis. API Design The one-line SitemapGenerator::create($url)->writeToFile($path) entry point covers the common case with almost no configuration, while the lower-level Sitemap/Url builder API remains available and consistently documented for cases needing manual control — a common pattern across Spatie’s package line that keeps the learning curve shallow.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search