PHPackages                             vursion/laravel-sitemappable - 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. vursion/laravel-sitemappable

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

vursion/laravel-sitemappable
============================

laravel-sitemappable

1.12.0(3mo ago)10462MITPHPPHP ^7.1 || ^7.2 || ^7.3 || ^7.4 || ^8.0 || ^8.1 || ^8.2 || ^8.3 || ^8.4 || ^8.5CI passing

Since May 17Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/vursion/laravel-sitemappable)[ Packagist](https://packagist.org/packages/vursion/laravel-sitemappable)[ Docs](https://github.com/vursion/laravel-sitemappable)[ GitHub Sponsors](https://github.com/vursion)[ RSS](/packages/vursion-laravel-sitemappable/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)Dependencies (4)Versions (15)Used By (0)

Laravel Sitemappable
====================

[](#laravel-sitemappable)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2369c58d1fe037794fc2f82f4a1bbeafab797038a39e8beaf8e1b823aa27f489/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f76757273696f6e2f6c61726176656c2d736974656d61707061626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vursion/laravel-sitemappable)[![Tests](https://github.com/vursion/laravel-sitemappable/workflows/tests/badge.svg)](https://github.com/vursion/laravel-sitemappable/workflows/tests/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/90ac6f6b3d830d185d7866dfb5103d68436a9e6db32db90216053ded813e7aa7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f76757273696f6e2f6c61726176656c2d736974656d61707061626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vursion/laravel-sitemappable)

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

[](#installation)

You can install the package via composer:

```
composer require vursion/laravel-sitemappable
```

***No need to register the service provider if you're using Laravel &gt;= 5.5. The package will automatically register itself.***Once the package is installed, you can register the service provider in `config/app.php` in the providers array:

```
'providers' => [
    ...
    Vursion\LaravelSitemappable\SitemappableServiceProvider::class
],
```

You need to publish the migration with:

```
php artisan vendor:publish --provider="Vursion\LaravelSitemappable\SitemappableServiceProvider" --tag=migrations
```

You should publish the `config/sitemappable.php` config file with:

```
php artisan vendor:publish --provider="Vursion\LaravelSitemappable\SitemappableServiceProvider" --tag=config
```

This is the content of the published config file:

```
return [

    /*
     * This is the name of the table that will be created by the migration and
     * used by the Sitemappable model shipped with this package.
     */
    'db_table_name' => 'sitemap',

    /*
     * The generated XML sitemap is cached to speed up performance.
     */
    'cache' => '60 minutes',

    /*
     * The batch import will loop through this directory and search for models
     * that use the IsSitemappable trait.
     */
    'model_directory' => 'app/Models',

    /*
     * If you're extending the controller, you'll need to specify the new location here.
     */
    'controller' => Vursion\LaravelSitemappable\Http\Controllers\SitemappableController::class,

];
```

Making a model sitemappable
---------------------------

[](#making-a-model-sitemappable)

The required steps to make a model sitemappable are:

- Add the `Vursion\LaravelSitemappable\IsSitemappable` trait.
- Define a public method `toSitemappableArray` that returns an array with the (localized) URL(s).
- Optionally define the conditions when a model should be sitemappable in a public method `shouldBeSitemappable`.

Here's an example of a model:

```
use Illuminate\Database\Eloquent\Model;
use Vursion\LaravelSitemappable\IsSitemappable;

class YourModel extends Model
{
    use IsSitemappable;

    public function toSitemappableArray()
    {
        return [];
    }

    public function shouldBeSitemappable()
    {
        return true;
    }
}
```

### toSitemappableArray

[](#tositemappablearray)

You need to return an array with (localized) URL(s) of your model.

```
public function toSitemappableArray()
{
    return [
        'nl' => 'https://www.vursion.io/nl/testen/test-slug-in-het-nederlands',
        'en' => 'https://www.vursion.io/en/tests/test-slug-in-english',
    ];
}
```

This is an example of a model that uses [ARCANDEDEV\\Localization](https://github.com/ARCANEDEV/Localization)for localized routes in combination with [spatie\\laravel-translatable](https://github.com/spatie/laravel-translatable)for making Eloquent models translatable.

```
public function toSitemappableArray()
{
    return collect(localization()->getSupportedLocalesKeys())->mapWithKeys(function ($key) {
        return [$key => localization()->getUrlFromRouteName($key, 'routes.your-route-name', ['slug' => $this->getTranslationWithoutFallback('slug', $key)])];
    });
}
```

### shouldBeSitemappable (conditionally sitemappable model instances)

[](#shouldbesitemappable-conditionally-sitemappable-model-instances)

Sometimes you may need to only make a model sitemappable under certain conditions. For example, imagine you have a `App\Models\Posts\Post` model. You may only want to allow "non-draft" and "published" posts to be sitemappable. To accomplish this, you may define a `shouldBeSitemappable` method on your model:

```
public function shouldBeSitemappable()
{
    return (! $this->draft && $this->published);
}
```

Rebuild the sitemap from scratch
--------------------------------

[](#rebuild-the-sitemap-from-scratch)

If you are installing Laravel Sitemappable into an existing project, you may already have database records you need to import into your sitemap. Laravel Sitemappable provides a `sitemappable:import` Artisan command that you may use to import all of your existing records into your sitemap:

```
php artisan sitemappable:import
```

Adding non-model associated routes
----------------------------------

[](#adding-non-model-associated-routes)

It's very likely your project will have routes that are not associated with a model. You can add these URLs by extending the controller and returning them via the `otherRoutes` method.

To publish the controller to `app/Http/Controllers/SitemappableController.php` run:

```
php artisan vendor:publish --provider="Vursion\LaravelSitemappable\SitemappableServiceProvider" --tag=controllers
```

Don't forget to change the location of the controller in the `config/sitemappable.php` config file:

```
return [

    ...

    /*
     * If you're extending the controller, you'll need to specify the new location here.
     */
    'controller' => App\Http\Controllers\SitemappableController::class,

    ...

];
```

Just make sure you return an array of arrays with key/value pairs like the example below:

```
public function otherRoutes()
{
    return [
        [
            'nl' => 'https://www.vursion.io/nl/contacteer-ons',
            'en' => 'https://www.vursion.io/en/contact-us',
        ],
        ...
    ];
}
```

Changelog
---------

[](#changelog)

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

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Jochen Sengier](https://github.com/celcius-jochen)

License
-------

[](#license)

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

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance81

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~136 days

Recently: every ~121 days

Total

14

Last Release

101d ago

PHP version history (7 changes)1.0.0PHP ^7.1 || ^8.0

1.2.0PHP ^7.1 || ^8.0 || ^8.1

1.3.0PHP ^7.1 || ^7.2 || ^7.3 || ^7.4 || ^8.0 || ^8.1

1.4.0PHP ^7.1 || ^7.2 || ^7.3 || ^7.4 || ^8.0 || ^8.1 || ^8.2

1.6.0PHP ^7.1 || ^7.2 || ^7.3 || ^7.4 || ^8.0 || ^8.1 || ^8.2 || ^8.3

1.8.0PHP ^7.1 || ^7.2 || ^7.3 || ^7.4 || ^8.0 || ^8.1 || ^8.2 || ^8.3 || ^8.4

1.10.0PHP ^7.1 || ^7.2 || ^7.3 || ^7.4 || ^8.0 || ^8.1 || ^8.2 || ^8.3 || ^8.4 || ^8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/b5d33f1ee1d57422623543dd00f0399ae238171eb7006b62ddfdc6640e679205?d=identicon)[jochensengier](/maintainers/jochensengier)

---

Top Contributors

[![jochensengier](https://avatars.githubusercontent.com/u/10118729?v=4)](https://github.com/jochensengier "jochensengier (31 commits)")

---

Tags

laravelphpsearch-engineseoxml-sitemapxml-sitemap-generatorlaravelSitemapvursion

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vursion-laravel-sitemappable/health.svg)

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

###  Alternatives

[fomvasss/laravel-meta-tags

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

3129.8k](/packages/fomvasss-laravel-meta-tags)[calotype/seo

A package containing SEO helpers.

742.6k](/packages/calotype-seo)[3x1io/filament-sitemap

Site Settings Like title, description, profile and Sitemap Generator

152.2k](/packages/3x1io-filament-sitemap)

PHPackages © 2026

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