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 by crawling your site or building them manually. Add extra URLs, set last-modified dates, and include models via a simple interface. Write sitemaps to disk with a fluent, developer-friendly API.

View on GitHub
Deep Wiki
Context7

Create and generate sitemaps with ease

Frequently asked questions about Laravel Sitemap
How do I generate a sitemap by crawling my Laravel site automatically?
Use `SitemapGenerator::create('https://your-site.com')->writeToFile($path)`. The package crawls your site recursively, respecting Laravel routes. Configure concurrency with `setConcurrency()` to avoid overloading shared hosting. Exclude URLs via `shouldCrawl()` callbacks.
Can I manually add URLs to a sitemap instead of crawling?
Yes. Use `Sitemap::create()->add(Url::create('/path')->setLastModificationDate(...))` to build sitemaps programmatically. This is ideal for dynamic routes or non-HTML content like APIs. Combine with crawling for hybrid sitemaps.
What Laravel versions does spatie/laravel-sitemap support?
The package officially supports Laravel 8+. For Laravel 7, check the CHANGELOG for compatibility notes, as some features may require adjustments. PHP 8.0+ is required due to underlying dependencies like spatie/crawler.
How do I add model entries (e.g., Blog posts) to a sitemap?
Implement the `Sitemapable` interface on your Eloquent model. Define `getSitemapUrl()` and `getLastModificationDate()` methods. The package will auto-detect and include these models when generating sitemaps via `SitemapGenerator`.
Is there a way to handle JavaScript-rendered content (SPAs) in sitemaps?
Yes, but it requires `spatie/browsershot` for headless Chrome rendering. Configure the crawler with `setCrawlerOptions(['browser' => true])` and ensure a Chrome binary is available. Note this adds complexity and may fail in CI/CD environments.
How do I optimize sitemap generation for large sites or shared hosting?
Reduce concurrency with `setConcurrency(1)` to avoid timeouts. Limit crawl depth with `setMaximumCrawlCount()`. For shared hosting, disable JS rendering and use manual URL additions for critical pages. Schedule generation via Artisan commands to avoid runtime conflicts.
Can I validate or test sitemaps before deploying to production?
Test manually generated sitemaps first with `Sitemap::create()->writeToFile()` to ensure correct URLs and metadata. For crawled sitemaps, mock `SitemapGenerator` in unit tests or validate against Google Search Console. Use `hasCrawled()` callbacks to debug excluded URLs.
What are the alternatives to spatie/laravel-sitemap for Laravel?
Alternatives include `kolapunch/laravel-sitemap` (simpler, less flexible) and `nuwave/lighthouse` (for GraphQL-driven sitemaps). However, spatie/laravel-sitemap stands out for its hybrid crawling/manual approach, model integration, and Laravel-native design.
How do I store sitemaps in cloud storage like S3?
Use Laravel’s filesystem disks. Pass a disk path to `writeToFile()`, e.g., `storage_path('app/sitemap.xml')` or `public_path('sitemap.xml')`. For S3, configure `filesystem_disks` in `config/filesystems.php` and use `storage_disk('s3')->path('sitemaps/sitemap.xml')`.
Why is my sitemap generation failing with 'Maximum execution time exceeded'?
This typically happens due to high concurrency or deep crawls. Reduce concurrency with `setConcurrency(2)` or limit crawl depth. For shared hosting, increase PHP’s `max_execution_time` in `php.ini` or split sitemaps into smaller chunks using `SitemapGenerator::create()->chunk(1000)`.
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai