PHPackages                             the\_elephpant/laravel-xml-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. the\_elephpant/laravel-xml-sitemap

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

the\_elephpant/laravel-xml-sitemap
==================================

A simple sitemap generator for PHP Framework.

1.0.1(2y ago)011MITPHPPHP ^7.1.3 || ^8.0

Since Apr 6Pushed 2y agoCompare

[ Source](https://github.com/TheElePHPant/laravel-sitemap)[ Packagist](https://packagist.org/packages/the_elephpant/laravel-xml-sitemap)[ Fund](https://paypal.me/helldar)[ Fund](https://yoomoney.ru/to/410012608840929)[ RSS](/packages/the-elephpant-laravel-xml-sitemap/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (3)Used By (0)

Sitemap for Laravel 5.6+
========================

[](#sitemap-for-laravel-56)

[![Laravel Sitemap](https://camo.githubusercontent.com/734364121f96ed81d256e051b40b8b830e6509ce05b5c03ca2279c64a286ee50/68747470733a2f2f707265766965772e647261676f6e2d636f64652e70726f2f546865447261676f6e436f64652f736974656d61702e7376673f6272616e643d6c61726176656c)](https://camo.githubusercontent.com/734364121f96ed81d256e051b40b8b830e6509ce05b5c03ca2279c64a286ee50/68747470733a2f2f707265766965772e647261676f6e2d636f64652e70726f2f546865447261676f6e436f64652f736974656d61702e7376673f6272616e643d6c61726176656c)

A simple sitemap generator for PHP Framework.

 [![StyleCI](https://camo.githubusercontent.com/48e8f1b1874a1d859a65889452aae8092d939c3ae2deef467806fbb1af73da1a/68747470733a2f2f7374796c6563692e696f2f7265706f732f37353633373238342f736869656c64)](https://styleci.io/repos/75637284) [![Total Downloads](https://camo.githubusercontent.com/5df72253e517c103db5e904615e0acd7120a6272e2dbf351489efad9b25dd847/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e647265792d68656c6c6461722f736974656d61702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andrey-helldar/sitemap) [![Latest Stable Version](https://camo.githubusercontent.com/bad3513a15d2b786f9901bc5ea21de46d062946a90c52ea82b2eebc70ad81f20/68747470733a2f2f706f7365722e707567782e6f72672f616e647265792d68656c6c6461722f736974656d61702f762f737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/andrey-helldar/sitemap) [![Latest Unstable Version](https://camo.githubusercontent.com/92fc9eedc337333c9de98b4b6fc0d2bd3f98feb401f3a9915ec1ebed9bcb9c12/68747470733a2f2f706f7365722e707567782e6f72672f616e647265792d68656c6c6461722f736974656d61702f762f756e737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/andrey-helldar/sitemap) [![License](https://camo.githubusercontent.com/05073f459c5bf8c910225e96f1e2127ff6f41c0e452a20b0aca868a1a3b52042/68747470733a2f2f706f7365722e707567782e6f72672f616e647265792d68656c6c6461722f736974656d61702f6c6963656e73653f666f726d61743d666c61742d737175617265)](LICENSE)

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

[](#installation)

For the 5.4 and 5.5 version of Laravel Framework, use [version 3](https://github.com/andrey-helldar/sitemap/tree/3.x).

To get the latest version of Laravel Sitemap, simply require the project using [Composer](https://getcomposer.org):

```
composer require andrey-helldar/sitemap

```

Instead, you may of course manually update your require block and run `composer update` if you so choose:

```
{
    "require": {
        "andrey-helldar/sitemap": "^5.0"
    }
}
```

If you don't use auto-discovery, add the `ServiceProvider` to the providers array in `config/app.php`:

```
Helldar\Sitemap\ServiceProvider::class,
```

You can also publish the config file to change implementations (ie. interface to specific class):

```
php artisan vendor:publish --provider="Helldar\Sitemap\ServiceProvider"

```

Now you can use a `app('sitemap')` method.

Upgrade Guides
--------------

[](#upgrade-guides)

- [Upgrading from 4.x to 5.x](guides/UPGRADE_4X_TO_5X.md)

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

[](#configuration)

To configure the generation, you need to fill the `models` array in the `config/sitemap.php` file:

```
'models' => [
    \App\User::class => [
        'route' => 'route.name',
        'route_parameters' => [
            'slug' => 'table_field_for_slug',
            'foo'  => 'table_field_for_foo',
            bar'  => 'my_relation.slug',
            'baz',
        ],
        'lastmod' => 'updated_at',
        'frequency' => 'daily',
        'priority'  => 0.8,
    ],
]
```

As the key of the array, you must use the model name for which the rules will be defined.

- **route** - the name of the route to generate the URL.
- **route\_parameters** - the parameters to be passed to the URL generation method, where:
    - the key is the parameter name for the routing. If the name of the routing parameter matches the name of the column in the database, you can specify only the value.
    - the value is the name of the column in the database to substitute the value. If the value needs to be taken from the link, then you should specify the appeal through a point. For example: `'bar' => 'my_relation.slug'`.
- **lastmod** - is the name of the column containing the record date. In case of absence, the current date is used. If the model does not need to take into account the time field, set the parameter `lastmod` to `false`.
- **frequency** - is the value of the refresh rate of the content. This is necessary for some search robots. You can also use constants from `Helldar\Sitemap\Services\Sitemap` class.
- **priority** - is the priority of the reference for model records.

If any of the model values are undefined, a global value will be used.

Using
-----

[](#using)

### Manual

[](#manual)

You can also transfer an array of items created manually:

```
use Carbon\Carbon;
use Helldar\Sitemap\Helpers\Variables;
use Helldar\Sitemap\Services\Sitemap;

$items_a = [];
$items_b = [];

for ($i = 0; $i < 3; $i++) {
    $item = app('sitemap')->makeItem()
        ->changefreq('weekly')
        ->lastmod(Carbon::now())
        ->loc("http://mysite.local/page/" . $i);

    array_push($items_a, $item);
}

for ($i = 0; $i < 3; $i++) {
    $item = app('sitemap')->makeItem()
        ->changefreq(Variables::FREQUENCY_WEEKLY)
        ->lastmod(Carbon::now())
        ->loc("http://mysite.local/offers/" . $i);

    array_push($items_b, $item);
}

return app('sitemap')
         ->manual($items_a, $items_b)
         ->show();
```

Returned:

```

        weekly
        2018-03-06T12:30:17+03:00
        http://mysite.local/page/0
        0.5

        weekly
        2018-03-06T12:38:24+03:00
        http://mysite.local/page/1
        0.5

        weekly
        2018-03-06T12:30:17+03:00
        http://mysite.local/page/2
        0.5

        weekly
        2018-03-06T12:30:17+03:00
        http://mysite.local/offers/0
        0.5

        weekly
        2018-03-06T12:38:24+03:00
        http://mysite.local/offers/1
        0.5

        weekly
        2018-03-06T12:30:17+03:00
        http://mysite.local/offers/2
        0.5

```

Also you can combine the data from the models builders with the transferred manually:

```
$query1 = \App\Catalog::query()->where('id', '>', '1000');
$query2 = \App\News::query()->where('category_id', 10);
$query3 = \App\Pages::query();

return app('sitemap')
         ->builders($query1, $query2, $query3)
         ->manual($items1, $items2, $items3)
         ->show();
```

### Images

[](#images)

Your can also transfer an array of image items created manually:

```
use Helldar\Sitemap\Services\Sitemap;

$items = [];

for ($i = 0; $i < 2; $i++) {
    $item = app('sitemap')->makeImages()
        ->loc("http://mysite.local/page/" . $i)
        ->image("http://mysite.local/images/1.jpg", "My Title 1-".$i, "Caption for image", "Limerick, Ireland", "Royalty free")
        ->image("http://mysite.local/images/2.jpg", "My Title 2-".$i)
        ->image("http://mysite.local/images/3.jpg");

    array_push($items, $item);
}

return app('sitemap')
         ->images($items)
         ->show();
```

Returned:

```

        http://mysite.local/page/0

            http://mysite.local/images/1.jpg
            My Title 1-0
            Caption for image
            Limerick, Ireland
            Royalty free

            http://mysite.local/images/2.jpg
            My Title 2-0

            http://mysite.local/images/3.jpg

        http://mysite.local/page/1

            http://mysite.local/images/1.jpg
            My Title 1-1
            Caption for image
            Limerick, Ireland
            Royalty free

            http://mysite.local/images/2.jpg
            My Title 2-1

            http://mysite.local/images/3.jpg

```

Attention! Due to the different structure of documents, when trying to call method `show()`, an image map will be shown only if there are no calls to other methods.

Example:

```
// Will show the image map.
return app('sitemap')
         ->images($items)
         ->show();

// Shows the map for `builders`. The image map will be ignored.
return app('sitemap')
         ->builders($query1, $query2, $query3)
         ->images($items)
         ->show();
```

The same principle applies when saving to one file - images will be ignored. But when saving to several files, the map will be successfully created.

### Show

[](#show)

To display the content on the screen, use the `show()` method:

```
$query1 = \App\Catalog::query()->where('id', '>', '1000');
$query2 = \App\News::query()->where('category_id', 10);
$query3 = \App\Pages::query();

return app('sitemap')
         ->builders($query1, $query2, $query3)
         ->show();
```

To return the content of the page, add any route:

```
app('route')->get('sitemap', function() {
    $query1 = \App\Catalog::query()->where('id', '>', '1000');
    $query2 = \App\News::query()->where('category_id', 10);
    $query3 = \App\Pages::query();

    return app('sitemap')
             ->builders($query1, $query2, $query3)
             ->show();
});
```

And go to your URL. Example: `http://mysite.dev/sitemap`.

### Save

[](#save)

#### If the option `separate_files` is DISABLED

[](#if-the-option-separate_files-is-disabled)

To save the contents to the file, use the `save()` method:

```
$query1 = \App\Catalog::query()->where('id', '>', '1000');
$query2 = \App\News::query()->where('category_id', 10);
$query3 = \App\Pages::query();

app('sitemap')
     ->builders($query1, $query2, $query3)
     ->save();
```

If you want to save multiple files, pass the path to the file as a parameter to the `save()` method:

```
$query1 = \App\Catalog::query()->where('id', '>', '1000');
$query2 = \App\News::query()->where('category_id', 10);
$query3 = \App\Pages::query();

app('sitemap')
     ->builders($query1, $query2, $query3)
     ->save('sitemap-1.xml');

app('sitemap')
     ->builders($query1, $query2, $query3)
     ->save('foo/bar/sitemap-2.xml');
```

#### If the option `separate_files` is ENABLED

[](#if-the-option-separate_files-is-enabled)

To save the contents to the separated files, use the `save()` method with `'separate_files' => true` parameter in [config/sitemap.php](src/config/sitemap.php) file.

```
$query1 = \App\Catalog::query()->where('id', '>', '1000');
$query2 = \App\News::query()->where('category_id', 10);
$query3 = \App\Pages::query();

app('sitemap')
     ->builders($query1, $query2, $query3)
     ->save();
```

In this case, the name of the file will be the default name from the settings: `'filename' => 'sitemap.xml'`. The files are saved through the `Storage` facade (see [config/sitemap.php](src/config/sitemap.php)).

Each model builder will be processed and saved in a separate file, and the shared file will contain references to it (with the selected a `public` storage name):

```
/storage/sitemap.xml   // general file
/storage/sitemap-1.xml // generated file for the $query1 collection
/storage/sitemap-2.xml // generated file for the $query2 collection
/storage/sitemap-3.xml // generated file for the $query3 collection

```

```

    2018-07-05T13:51:40+00:00
    http://example.com/storage/sitemap-1.xml

    2018-07-05T13:51:41+00:00
    http://example.com/storage/sitemap-2.xml

    2018-07-05T13:51:41+00:00
    http://example.com/storage/sitemap-3.xml

```

If you use a multi-domain application, you can specify the domain names of the generated links to other files, having pre-specified them in the settings:

```
'domains' => [
    'foo' => env('APP_URL'), // http://example.com
    'bar' => 'http://foo.bar',
],
```

```
app('sitemap')
     ->builders($query1, $query2, $query3)
     ->domain('foo')
     ->save();

app('sitemap')
     ->builders($query1, $query2, $query3)
     ->domain('bar')
     ->save();
```

This method will create files with the following links:

```

    2018-07-05T13:51:40+00:00
    http://example.com/storage/sitemap-1.xml

    2018-07-05T13:51:41+00:00
    http://example.com/storage/sitemap-2.xml

    2018-07-05T13:51:41+00:00
    http://example.com/storage/sitemap-3.xml

```

and

```

    2018-07-05T13:51:40+00:00
    http://foo.bar/storage/sitemap-1.xml

    2018-07-05T13:51:41+00:00
    http://foo.bar/storage/sitemap-2.xml

    2018-07-05T13:51:41+00:00
    http://foo.bar/storage/sitemap-3.xml

```

By default, the domain specified in `APP_URL` of `.env` file will be used.

If you want to save multiple files, pass the path to the file as a parameter to the `save($path)` method with `'separate_files' => true` parameter in [config/sitemap.php](src/config/sitemap.php) file:

```
$query1 = \App\Catalog::query()->where('id', '>', '1000');
$query2 = \App\News::query()->where('category_id', 10);
$query3 = \App\Pages::query();

$manual_items = [];

for ($i = 0; $i < 3; $i++) {
    $item = app('sitemap')->makeItem()
        ->changefreq('weekly')
        ->lastmod(Carbon\Carbon::now())
        ->loc("http://mysite.local/page/" . $i);

    array_push($manual_items, $item);
}

app('sitemap')
     ->builders($query1, $query2, $query3)
     ->manual($manual_items)
     ->save(public_path('first.xml'));

app('sitemap')
     ->builders($query1, $query2, $query3)
     ->manual($manual_items)
     ->save(storage_path('foo/bar/second.xml'));
```

Files will be created:

```
/storage/first.xml   // general file
/storage/first-1.xml // generated file for the $query1 collection
/storage/first-2.xml // generated file for the $query2 collection
/storage/first-3.xml // generated file for the $query3 collection
/storage/first-4.xml // generated file for the $manual_items collection

/storage/foo/bar/second.xml   // general file
/storage/foo/bar/second-1.xml // generated file for the $query1 collection
/storage/foo/bar/second-2.xml // generated file for the $query2 collection
/storage/foo/bar/second-3.xml // generated file for the $query3 collection
/storage/foo/bar/second-4.xml // generated file for the $manual_items collection

```

SEO
---

[](#seo)

Sitemap is extremely useful when indexing a site by search bots. If you use a sitemap splitting into several files, you only need to add a link to the main file in the `robots.txt` file.

For example, you created several files:

```
/storage/sitemaps/promo.xml
/storage/sitemaps/promo-1.xml
/storage/sitemaps/promo-2.xml
/storage/sitemaps/promo-3.xml

```

In the `robots.txt` file, you only need to specify a link to the main file:

```
Sitemap: http://example.com/storage/sitemaps/promo.xml

```

All the rest of the search bots will do for you.

Enjoy!

License
-------

[](#license)

This package is licensed under the [MIT License](LICENSE).

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.4% 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 ~133 days

Total

2

Last Release

998d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3a2d00b4c1f827d240c57984df9da59b4fc23bc3ba33551e106cfa1ca283f17b?d=identicon)[TheElePHPant](/maintainers/TheElePHPant)

---

Top Contributors

[![TheElePHPant](https://avatars.githubusercontent.com/u/113602095?v=4)](https://github.com/TheElePHPant "TheElePHPant (5 commits)")[![Webakula](https://avatars.githubusercontent.com/u/35304239?v=4)](https://github.com/Webakula "Webakula (2 commits)")

---

Tags

laravelgeneratorSimpleSitemapseoseparated filesseo optimized

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/the-elephpant-laravel-xml-sitemap/health.svg)

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[fomvasss/laravel-meta-tags

A package to manage SEO (meta-tags, xml-fields, etc.)

3028.9k](/packages/fomvasss-laravel-meta-tags)[kphoen/sitemap-generator

Provides a way to create/generate a sitemap using Propel, Doctrine, etc.

1687.8k4](/packages/kphoen-sitemap-generator)

PHPackages © 2026

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