PHPackages                             watson/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. watson/sitemap

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

watson/sitemap
==============

Generate Google Sitemaps in Laravel

5.6.0(1mo ago)2681.4M↓36.7%40[7 issues](https://github.com/dwightwatson/sitemap/issues)[2 PRs](https://github.com/dwightwatson/sitemap/pulls)4MITPHPPHP ^8.0CI failing

Since Mar 7Pushed 1mo ago10 watchersCompare

[ Source](https://github.com/dwightwatson/sitemap)[ Packagist](https://packagist.org/packages/watson/sitemap)[ RSS](/packages/watson-sitemap/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (8)Versions (48)Used By (4)

Sitemap for Laravel
===================

[](#sitemap-for-laravel)

[![Build Status](https://camo.githubusercontent.com/6eb4b7c49cfc484aaa2e2a5c34c52ad59c2685ada61cc88715c5ad9001369281/68747470733a2f2f7472617669732d63692e6f72672f647769676874776174736f6e2f736974656d61702e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/dwightwatson/sitemap)[![Total Downloads](https://camo.githubusercontent.com/b97da7aad34707bac845f7768d8ba4885142ad98bfc2c32b04ae214ec190df47/68747470733a2f2f706f7365722e707567782e6f72672f776174736f6e2f736974656d61702f646f776e6c6f6164732e737667)](https://packagist.org/packages/watson/sitemap)[![Latest Stable Version](https://camo.githubusercontent.com/a79b865947a04640b52f0cb17882e82de0f4f2cd999c03ca5a9266a77cd42e91/68747470733a2f2f706f7365722e707567782e6f72672f776174736f6e2f736974656d61702f762f737461626c652e737667)](https://packagist.org/packages/watson/sitemap)[![Latest Unstable Version](https://camo.githubusercontent.com/1782187ebc5003fce32d5c4e316f9be400df82c661aa991b18908413ba6692fd/68747470733a2f2f706f7365722e707567782e6f72672f776174736f6e2f736974656d61702f762f756e737461626c652e737667)](https://packagist.org/packages/watson/sitemap)[![License](https://camo.githubusercontent.com/1b04f759848abb680c37ce5607f855dd61e2d06d1dc2fb3417c312c3e0a254c2/68747470733a2f2f706f7365722e707567782e6f72672f776174736f6e2f736974656d61702f6c6963656e73652e737667)](https://packagist.org/packages/watson/sitemap)

Sitemap is a package built specifically for Laravel that will help you generate XML sitemaps for Google. Based on [laravel-sitemap](https://github.com/RoumenDamianoff/laravel-sitemap) this package operates in a slightly different way to better fit the needs of our project. A facade is used to access the sitemap class and we have added the ability to produce sitemap indexes as well as sitemaps. Furthermore, it's tested.

Read more about sitemaps and how to use them efficiently on [Google Webmaster Tools](https://support.google.com/webmasters/answer/156184?hl=en).

Installation
------------

[](#installation)

```
composer require watson/sitemap
```

Usage
-----

[](#usage)

### Creating sitemap indexes

[](#creating-sitemap-indexes)

If you have a large number of links (50,000+) you will want to break your sitemaps out into seperate sitemaps with a sitemap index linking them all. You add sitemap indexes using `Sitemap::addSitemap($location, $lastModified)` and then you return the sitemap index with `Sitemap::renderSitemapIndex()`. The `$lastModified` variable will be parsed and converted to the right format for a sitemap.

Here is an example controller that produces a sitemap index.

```
namespace App\Http\Controllers;

use Sitemap;

class SitemapsController extends Controller
{
    public function index()
    {
        // Get a general sitemap.
        Sitemap::addSitemap('/sitemaps/general');

        // You can use the route helpers too.
        Sitemap::addSitemap(route('sitemaps.posts'));

        // Return the sitemap to the client.
        return Sitemap::index();
    }
}
```

Simply route to this as you usually would, `Route::get('sitemap', 'SitemapsController@index');`.

### Creating sitemaps

[](#creating-sitemaps)

Similarly to sitemap indexes, you just add tags for each item in your sitemap using `Sitemap::addTag($location, $lastModified, $changeFrequency, $priority)`. You can return the sitemap with `Sitemap::renderSitemap()`. Again, the `$lastModified` variable will be parsed and convered to the right format for the sitemap.

If you'd like to just get the raw XML, simply call `Sitemap::xml()`.

Here is an example controller that produces a sitemap for blog posts.

```
namespace App\Http\Controllers;

use Post;
use Sitemap;

class SitemapsController extends Controller
{
    public function posts()
    {
        $posts = Post::all();

        foreach ($posts as $post) {
            Sitemap::addTag(route('posts.show', $post), $post->updated_at, 'daily', '0.8');
        }

        return Sitemap::render();
    }
}
```

If you just want to pass a model's `updated_at` timestamp as the last modified parameter, you can simply pass the model as the second parameter and the sitemap will use that attribute automatically.

**If you're pulling a lot of records from your database you might want to consider restricting the amount of data you're getting by using the `select()` method. You can also use the `chunk()` method to only load a certain number of records at any one time as to not run out of memory.**

### Image sitemaps

[](#image-sitemaps)

You can use Google image extensions for sitemaps to give Google more information about the images available on your pages. [Read the specification](https://support.google.com/webmasters/answer/178636?hl=en)

Images are associated with page and you can use up to 1000 images per page.

Here is an example of adding image tag to usual page tag.

```
namespace App\Http\Controllers;

use Page;
use Sitemap;

class SitemapsController extends Controller
{
    public function pages()
    {
        $pages = Page::all();

        foreach ($pages as $page) {
            $tag = Sitemap::addTag(route('pages.show', $page), $page->updated_at, 'daily', '0.8');

            foreach ($page->images as $image) {
                $tag->addImage($image->url, $image->caption);
            }
        }

        return Sitemap::render();
    }
}
```

Here is the full list of arguments to add an image to a tag.

```
$tag->addImage($location, $caption, $geoLocation, $title, $licenceUrl);
```

Configuration
-------------

[](#configuration)

To publish the configuration file for the sitemap package, simply run this Artisan command:

```
php artisan config:publish watson/sitemap

php artisan vendor:publish --provider="Watson\Sitemap\SitemapServiceProvider"
```

Then take a look in `config/sitemap.php` to see what is available.

### Caching

[](#caching)

By default, caching is disabled. If you would like to enable caching, simply set `cache_enabled` in the configuration file to `true`. You can then specify how long you would like your views to be cached for. Keep in mind that when enabled, caching will affect each and every request made to the sitemap package.

### Multilingual tags

[](#multilingual-tags)

If you'd like to use a mutlilingual tag, simply pass an instance of one to the `addTag` method. Below is a crude example of how you would pass alternate tag locations for different languages.

```
Sitemap::addTag(new \Watson\Sitemap\Tags\MultilingualTag(
    $location,
    $lastModified,
    $changeFrequency,
    $priority,
    [
        'en' => $location . '?lang=en',
        'fr' => $location . '?lang=fr'
    ]
));
```

###  Health Score

69

—

FairBetter than 100% of packages

Maintenance87

Actively maintained with recent releases

Popularity59

Moderate usage in the ecosystem

Community32

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 72.6% 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 ~98 days

Recently: every ~108 days

Total

46

Last Release

59d ago

Major Versions

1.1.4 → 2.0.142016-08-18

1.1.x-dev → 2.0.182016-11-21

2.1.0 → 3.0.12020-03-04

3.0.2 → 4.0.02020-09-09

3.0.x-dev → 5.0.02022-02-08

PHP version history (7 changes)1.0.0PHP &gt;=5.3.0

2.0.1PHP &gt;=5.4.0

3.0.1PHP ^7.2.5

4.0.0PHP ^7.3

4.0.1PHP ^7.3 | ^8.0

3.0.x-devPHP ~8.0

5.0.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1100408?v=4)[Dwight Watson](/maintainers/dwightwatson)[@dwightwatson](https://github.com/dwightwatson)

---

Top Contributors

[![dwightwatson](https://avatars.githubusercontent.com/u/1100408?v=4)](https://github.com/dwightwatson "dwightwatson (98 commits)")[![browner12](https://avatars.githubusercontent.com/u/5232313?v=4)](https://github.com/browner12 "browner12 (5 commits)")[![SanderMuller](https://avatars.githubusercontent.com/u/9074391?v=4)](https://github.com/SanderMuller "SanderMuller (4 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (4 commits)")[![imanghafoori1](https://avatars.githubusercontent.com/u/6961695?v=4)](https://github.com/imanghafoori1 "imanghafoori1 (3 commits)")[![jrean](https://avatars.githubusercontent.com/u/5646128?v=4)](https://github.com/jrean "jrean (3 commits)")[![KristobalJunta](https://avatars.githubusercontent.com/u/6359247?v=4)](https://github.com/KristobalJunta "KristobalJunta (3 commits)")[![RobertBoes](https://avatars.githubusercontent.com/u/2871897?v=4)](https://github.com/RobertBoes "RobertBoes (2 commits)")[![seolover](https://avatars.githubusercontent.com/u/1481909?v=4)](https://github.com/seolover "seolover (2 commits)")[![davecarlson](https://avatars.githubusercontent.com/u/299702?v=4)](https://github.com/davecarlson "davecarlson (2 commits)")[![simonschaufi](https://avatars.githubusercontent.com/u/941794?v=4)](https://github.com/simonschaufi "simonschaufi (2 commits)")[![xAockd](https://avatars.githubusercontent.com/u/3390348?v=4)](https://github.com/xAockd "xAockd (1 commits)")[![hootlex](https://avatars.githubusercontent.com/u/6147968?v=4)](https://github.com/hootlex "hootlex (1 commits)")[![janbolat](https://avatars.githubusercontent.com/u/6511056?v=4)](https://github.com/janbolat "janbolat (1 commits)")[![neochief](https://avatars.githubusercontent.com/u/121889?v=4)](https://github.com/neochief "neochief (1 commits)")[![oillescas](https://avatars.githubusercontent.com/u/1347045?v=4)](https://github.com/oillescas "oillescas (1 commits)")[![repat](https://avatars.githubusercontent.com/u/516807?v=4)](https://github.com/repat "repat (1 commits)")[![shaggyz](https://avatars.githubusercontent.com/u/1447280?v=4)](https://github.com/shaggyz "shaggyz (1 commits)")

---

Tags

laravelphpsitemaplaravelsitemaps

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)[zidbih/laravel-deadlock

Make temporary Laravel workarounds expire and fail CI when ignored.

985.4k](/packages/zidbih-laravel-deadlock)

PHPackages © 2026

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