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.
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).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.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.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.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.$sitemap->add(route('posts.show', $post), $post->updated_at, 0.8, 'weekly'). Using route() keeps you honest about locale/domain handling; hardcoded strings drift.store each as its own file, then build a second sitemap that references them as child sitemaps. Submit only the index to search engines.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.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.add() parameters (images, title, alternates) for image sitemaps and hreflang; they pass through to the generated XML without needing a custom template.Sitemap: at your index URL and let it manage the line instead of hand-editing robots.txt.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.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.& or non-ASCII slugs need escaping enabled in config; otherwise validators reject the file with cryptic XML errors.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.<lastmod> format (Y-m-d or full ISO 8601) and that every <loc> is absolute and reachable without a redirect.config/sitemap.php and the published view, not in a fork — that keeps future upgrades (like this one) painless.How can I help you explore Laravel packages today?