PHPackages                             spatie/laravel-sitemap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. spatie/laravel-sitemap

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

spatie/laravel-sitemap
======================

Create and generate sitemaps with ease

8.2.0(1w ago)2.6k16.6M↓24.8%299[1 PRs](https://github.com/spatie/laravel-sitemap/pulls)20MITPHPPHP ^8.4CI passing

Since Aug 15Pushed 5d ago33 watchersCompare

[ Source](https://github.com/spatie/laravel-sitemap)[ Packagist](https://packagist.org/packages/spatie/laravel-sitemap)[ Docs](https://github.com/spatie/laravel-sitemap)[ Fund](https://spatie.be/open-source/support-us)[ RSS](/packages/spatie-laravel-sitemap/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (10)Dependencies (38)Versions (85)Used By (20)

 [   ![Logo for laravel-sitemap](https://camo.githubusercontent.com/90cac106d0da71a0b926c964b3aec5f649cad58f605632da37b760fd817c42aa/68747470733a2f2f7370617469652e62652f7061636b616765732f6865616465722f6c61726176656c2d736974656d61702f68746d6c2f6c696768742e77656270)  ](https://spatie.be/open-source?utm_source=github&utm_medium=banner&utm_campaign=laravel-sitemap)Generate sitemaps with ease
===========================

[](#generate-sitemaps-with-ease)

[![Latest Version on Packagist](https://camo.githubusercontent.com/88bfde272b18b434ba0112ed83db106ec6241140702a7c70dc3f46300d738146/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d736974656d61702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-sitemap)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Test Status](https://github.com/spatie/laravel-sitemap/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-sitemap/actions/workflows/run-tests.yml)[![Code Style Status](https://github.com/spatie/laravel-sitemap/actions/workflows/fix-php-code-style-issues.yml/badge.svg)](https://github.com/spatie/laravel-sitemap/actions/workflows/fix-php-code-style-issues.yml)[![PHPStan](https://github.com/spatie/laravel-sitemap/actions/workflows/phpstan.yml/badge.svg)](https://github.com/spatie/laravel-sitemap/actions/workflows/phpstan.yml)[![Total Downloads](https://camo.githubusercontent.com/7df68800620b7449bd11d4be7273456d279b63ec1c504041efb002706668a284/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d736974656d61702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-sitemap)

This package can generate a sitemap without you having to add URLs to it manually. This works by crawling your entire site.

```
use Spatie\Sitemap\SitemapGenerator;

SitemapGenerator::create('https://example.com')->writeToFile($path);
```

You can also create your sitemap manually:

```
use Carbon\Carbon;
use Spatie\Sitemap\Sitemap;
use Spatie\Sitemap\Tags\Url;

Sitemap::create()
    ->add(Url::create('/home')
        ->setLastModificationDate(Carbon::yesterday()))
    ->add(...)
    ->writeToFile($path);
```

Or you can have the best of both worlds by generating a sitemap and then adding more links to it:

```
use Spatie\Sitemap\SitemapGenerator;
use Spatie\Sitemap\Tags\Url;

SitemapGenerator::create('https://example.com')
    ->getSitemap()
    ->add(Url::create('/extra-page')
        ->setLastModificationDate(Carbon::yesterday()))
    ->add(...)
    ->writeToFile($path);
```

Splitting a crawl into multiple sitemaps
----------------------------------------

[](#splitting-a-crawl-into-multiple-sitemaps)

Sometimes you want the crawled URLs grouped into separate sitemap files (for example one for your blog and one for the rest of the site). This makes it easier to track indexing coverage per section in Google Search Console.

Pass a closure to `writeToFile`. It receives each `Url` and returns the path of the file that URL belongs in.

```
use Spatie\Sitemap\SitemapGenerator;
use Spatie\Sitemap\Tags\Url;

SitemapGenerator::create('https://example.com')
    ->writeToFile(fn (Url $url) => str_starts_with($url->path(), '/blog')
        ? public_path('sitemap-blog.xml')
        : public_path('sitemap-pages.xml'));
```

Returning `null` from the closure leaves that URL out of every sitemap.

By default no sitemap index is written. Call `sitemapIndexPath` to also generate an index that references each written sitemap.

```
SitemapGenerator::create('https://example.com')
    ->sitemapIndexPath(public_path('sitemap.xml'))
    ->writeToFile(fn (Url $url) => str_starts_with($url->path(), '/blog')
        ? public_path('sitemap-blog.xml')
        : public_path('sitemap-pages.xml'));
```

When you combine this with `maxTagsPerSitemap()`, a group that exceeds the limit is split further into numbered files (`sitemap-blog_0.xml`, `sitemap-blog_1.xml`), each listed in the index.

You can also add your models directly by implementing the `Sitemapable` interface.

```
use Spatie\Sitemap\Contracts\Sitemapable;
use Spatie\Sitemap\Tags\Url;

class Post extends Model implements Sitemapable
{
    public function toSitemapTag(): Url | string | array
    {
        return route('blog.post.show', $this);
    }
}
```

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/a1b18bf42ae6dc175e8ce4bc65f99fc532385ec97d4aacfe2c0df058ff87b00e/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d736974656d61702e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-sitemap)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Documentation
-------------

[](#documentation)

All documentation is available [on our documentation site](https://spatie.be/docs/laravel-sitemap).

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you've found a bug regarding security please mail  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

84

—

ExcellentBetter than 100% of packages

Maintenance99

Actively maintained with recent releases

Popularity76

Solid adoption and visibility

Community52

Growing community involvement

Maturity96

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 63.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~44 days

Recently: every ~30 days

Total

82

Last Release

10d ago

Major Versions

3.3.1 → 4.02018-02-08

4.0 → 5.0.02018-03-02

5.9.2 → 6.0.02021-03-12

6.4.0 → 7.0.02023-10-24

7.4.0 → 8.0.02026-02-21

PHP version history (9 changes)0.0.1PHP ^7.0

4.0PHP ^7.1

5.3.0PHP ^7.2

5.9.0PHP ^7.4|^8.0

6.0.0PHP ^8.0

7.1.0PHP ^8.2

7.3.0PHP ^8.2||^8.3||^8.4

7.4.0PHP ^8.2||^8.3||^8.4||^8.5

8.0.1PHP ^8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (239 commits)")[![brendt](https://avatars.githubusercontent.com/u/6905297?v=4)](https://github.com/brendt "brendt (26 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (22 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (12 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (9 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (9 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (8 commits)")[![ManuDoni](https://avatars.githubusercontent.com/u/10022459?v=4)](https://github.com/ManuDoni "ManuDoni (6 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (5 commits)")[![BrentRobert](https://avatars.githubusercontent.com/u/6866325?v=4)](https://github.com/BrentRobert "BrentRobert (3 commits)")[![emanuelmutschlechner](https://avatars.githubusercontent.com/u/27734375?v=4)](https://github.com/emanuelmutschlechner "emanuelmutschlechner (3 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (3 commits)")[![king724](https://avatars.githubusercontent.com/u/350488?v=4)](https://github.com/king724 "king724 (2 commits)")[![Akilez](https://avatars.githubusercontent.com/u/2991685?v=4)](https://github.com/Akilez "Akilez (2 commits)")[![Briareos17](https://avatars.githubusercontent.com/u/2332158?v=4)](https://github.com/Briareos17 "Briareos17 (2 commits)")[![jimirobaer](https://avatars.githubusercontent.com/u/8984769?v=4)](https://github.com/jimirobaer "jimirobaer (2 commits)")[![madman-81](https://avatars.githubusercontent.com/u/50033071?v=4)](https://github.com/madman-81 "madman-81 (2 commits)")[![bakerkretzmar](https://avatars.githubusercontent.com/u/18192441?v=4)](https://github.com/bakerkretzmar "bakerkretzmar (2 commits)")[![pascalbaljet](https://avatars.githubusercontent.com/u/8403149?v=4)](https://github.com/pascalbaljet "pascalbaljet (2 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (2 commits)")

---

Tags

googlelaravelphpseositemapxmlspatielaravel-sitemap

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/spatie-laravel-sitemap/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-laravel-sitemap/health.svg)](https://phpackages.com/packages/spatie-laravel-sitemap)
```

###  Alternatives

[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k9.0M69](/packages/spatie-laravel-responsecache)[spatie/laravel-health

Monitor the health of a Laravel application

87512.0M165](/packages/spatie-laravel-health)[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.8k3.8M508](/packages/pimcore-pimcore)[nativephp/mobile

NativePHP for Mobile

1.1k75.1k91](/packages/nativephp-mobile)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
