nik / laravel-sitemap
Laravel Sitemap package for Laravel.
v10.0.0
2026-05-26 07:16 UTC
Requires
- php: ^8.2
- illuminate/contracts: ^10.0|^11.0|^12.0|^13.0
- illuminate/filesystem: ^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
Requires (Dev)
- driftingly/rector-laravel: ^2.3
- larastan/larastan: ^3.9
- laravel/pint: ^1.14
- orchestra/testbench: ^8.0|^9.0|^10.0|^11.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.1
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- rector/rector: ^2.4
README
A powerful and easy-to-use sitemap generator for Laravel. Support for Google News, Images, Videos, and Multilingual sitemaps.
Features
- Supports Laravel 10, 11, 12, and 13.
- PHP 8.2+ Compatibility.
- Dynamic sitemap generation.
- Automatic caching.
- Support for Big Sitemaps (Sitemap Index).
- Google News, Images, Videos, and Multilingual support.
- Multiple output formats (XML, HTML, TXT).
Requirements
- PHP 8.2 or higher.
- Laravel 10, 11, 12, or 13.
Installation
Install the package via composer:
composer require nikhil/laravel-sitemap
(Optional) Publish the configuration file, views, or assets:
php artisan vendor:publish --tag="sitemap-config" php artisan vendor:publish --tag="sitemap-views" php artisan vendor:publish --tag="sitemap-assets"
Quick Start
Generate a simple sitemap in your routes/web.php:
use Nikhil\Sitemap\Sitemap; Route::get('sitemap.xml', function () { /** @var Sitemap $sitemap */ $sitemap = app('sitemap'); // Add static pages $sitemap->add(url('/'), now(), '1.0', 'daily'); $sitemap->add(url('contact'), now(), '0.7', 'monthly'); // Add dynamic items from database $posts = \App\Models\Post::latest()->get(); foreach ($posts as $post) { $sitemap->add(url($post->slug), $post->updated_at, '0.9', 'weekly'); } return $sitemap->render('xml'); });
Advanced Usage
For more detailed examples, please refer to the EXAMPLES.md file.
Common Scenarios:
- Caching: Speed up your sitemap generation.
- Big Sitemaps: Handling more than 50k items.
- Save to File: Generate sitemap via Artisan commands.
- Images & Videos: Add media to your sitemap items.
- Multilingual: Support for
hreflangtags.
Development
Run the package checks locally:
composer format:test
composer analyse
composer refactor
composer test
To run tests with coverage, enable a coverage driver such as Xdebug or PCOV, then run:
composer test-coverage
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
This package is open-sourced software licensed under the MIT license.