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.
SitemapGenerator) and manual control (explicit Url definitions), offering flexibility for complex sites (e.g., dynamic content + static pages).Sitemapable interface) for custom logic, enabling integration with existing model-based workflows (e.g., Eloquent models).SitemapIndex for large sites (e.g., segmented by content type) and compliance with Google’s sitemap size limits.spatie/browsershot) for SPAs or JS-heavy sites, though adds complexity (dependency management, performance overhead).setConcurrency() and setMaximumCrawlCount().Sitemapable interface requires model modifications, which may conflict with existing logic or migrations. Mitigation: Use trait-based implementations or middleware.lastmod dates or missing priority/changefreq tags could hurt rankings. Mitigation: Validate sitemap output and use manual overrides where needed.browsershot adds ~50MB to deployment (Chrome binary). Mitigation: Only enable for JS-heavy sites.priority, changefreq)?route() helpers), Eloquent models, and filesystem disks. Complements packages like spatie/backups (for sitemap archiving) or spatie/laravel-activitylog (for tracking sitemap changes).SitemapGenerator in unit tests).Url definitions) for critical pages (e.g., /about, /blog).shouldCrawl() to exclude non-essential pages (e.g., /admin, /webhooks)./posts-sitemap.xml, /pages-sitemap.xml).Sentry).ping /sitemap.xml).cURL, DOM, and fileinfo extensions (standard in Laravel).cache()->remember()) for performance; configure config/sitemap.php if needed.composer require spatie/laravel-sitemap.php artisan vendor:publish --tag=sitemap-config.SitemapGenerator::create(url('/'))->writeToFile(public_path('sitemap.xml'));
Sitemapable for Eloquent models (e.g., Post):
class Post implements Sitemapable {
public function toSitemapTag(): Url { ... }
}
config/sitemap.php or via closures.routes/console.php:
Schedule::command('sitemap:generate')->daily();
config/sitemap.php) reduces drift risk, but changes require redeployment.Sitemapable models may break sitemap generation if not validated.spatie/crawler updates may alter crawling behavior; test after major versions.browsershot requires Chrome binary updates; automate via CI/CD.SitemapGenerator::debug() to log crawled URLs and errors.guzzle_options timeouts or reduce concurrency.hasCrawled() to deduplicate or filter.SitemapIndex.setMaximumCrawlCount() to limit load.cache()->remember()) to avoid regenerated on every request.sitemap:generate command in queue).SitemapIndex.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Crawler times out | Incomplete sitemap | Increase timeouts, reduce concurrency |
| JS execution fails | Missed client-side URLs | Fallback to manual URL addition |
Model toSitemapTag() errors |
Broken sitemap links | Validate models, use try-catch in implementation |
| Storage permission issues |
How can I help you explore Laravel packages today?