Weave 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

Sitemap Laravel Package

andrey-helldar/sitemap

A Laravel package for generating XML sitemaps and sitemap indexes with ease. It supports multiple sitemap files, automatic index creation, caching, and flexible configuration, helping search engines discover and crawl your site's pages efficiently.

View on GitHub
Deep Wiki
Context7

Getting Started

  • composer require thedragoncode/sitemap, then publish config: php artisan vendor:publish --provider="TheDragonCode\Sitemap\SitemapServiceProvider" --tag=config (add --tag=views if you want to customise the XSL stylesheet).
  • Open config/sitemap.php first — it holds use_cache, cache_key, cache_duration, max_size, max_file_size, sitemap_path, sitemap_url and escaping, and most day-to-day surprises live here.
  • Resolve the service (Sitemap facade or injected TheDragonCode\Sitemap\Sitemap) and use add($url, $lastmod, $priority, $changefreq) to build, then store('xml', 'sitemap') to write public/sitemap.xml or render('xml') to stream it from a route.
  • First use case: a scheduled command that pulls Post::published()->get() and emits one <url> per record, storing to public/, plus a GET /sitemap.xml route that serves it. That single flow covers 80% of real projects.

Implementation Patterns

  • Command-driven generation. Put the build in app/Console/Commands/GenerateSitemap.php and schedule it ($schedule->command('sitemap:generate')->daily()), rather than generating on every request. Keeps web requests fast and makes failures observable.
  • Model → URL mapping. Loop results and call $sitemap->add(route('posts.show', $post), $post->updated_at, 0.8, 'weekly'). Using route() keeps you honest about locale/domain handling; hardcoded strings drift.
  • Sitemap indexes for scale. When you exceed ~50,000 URLs or 50MB, split by section (posts, products, categories), store each as its own file, then build a second sitemap that references them as child sitemaps. Submit only the index to search engines.
  • On-the-fly render for small sites. Route::get('sitemap.xml', fn () => $sitemap->render('xml')) with the package cache enabled is fine for a few hundred URLs; skip it once generation takes more than a second.
  • Cache discipline. With use_cache on, the rendered output is cached under cache_key. After content changes, either bump the key, call the cache-forget helper, or disable caching and rely on the scheduled job.
  • Custom tags and alternates. Use the extra add() parameters (images, title, alternates) for image sitemaps and hreflang; they pass through to the generated XML without needing a custom template.
  • Robots integration. If the package's robots hook is enabled in config, point Sitemap: at your index URL and let it manage the line instead of hand-editing robots.txt.

Gotchas and Tips

  • v5.5.0 is a Laravel 9 compatibility bump. It is the release line to use on Laravel 9 / PHP 8.0+. If you are pinned to Laravel 8 or older, stay on 5.4.x — do not assume 5.5.0 is a drop-in there. Verify your composer.json constraint before composer update.
  • max_file_size only applies on store(). render() streams whatever you built; it will not split for you. If you rely on automatic splitting, generate and store, don't render.
  • Paths are relative to public/. sitemap_path resolves from the public directory, so on deployments with a symlinked public_html confirm files land where the web server expects. Add the generated XML to .gitignore and generate on deploy.
  • Escaping bites on query strings. URLs with & or non-ASCII slugs need escaping enabled in config; otherwise validators reject the file with cryptic XML errors.
  • Memory, not CPU, is the usual failure. Use chunk()/cursor() over get() for large tables, and raise set_time_limit in the command — a sitemap job that dies silently usually hit the memory limit, not an exception.
  • Debug by inspecting the XML. When search engines complain, open the generated file directly and check <lastmod> format (Y-m-d or full ISO 8601) and that every <loc> is absolute and reachable without a redirect.
  • Extension points are the config and published views. Custom XSL styling and per-environment overrides belong in config/sitemap.php and the published view, not in a fork — that keeps future upgrades (like this one) painless.
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.
diephp/sequences
users-au/socialite-provider
twidpay/twid-logger
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle