PHPackages                             bkwld/sitemap-from-routes - 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. bkwld/sitemap-from-routes

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

bkwld/sitemap-from-routes
=========================

Generate a sitemap directly from your route definitions

1.0.0(8y ago)1310[3 issues](https://github.com/BKWLD/sitemap-from-routes/issues)MITPHPPHP &gt;=5.3.0

Since Sep 8Pushed 8y ago1 watchersCompare

[ Source](https://github.com/BKWLD/sitemap-from-routes)[ Packagist](https://packagist.org/packages/bkwld/sitemap-from-routes)[ RSS](/packages/bkwld-sitemap-from-routes/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Sitemap from Routes
===================

[](#sitemap-from-routes)

Generate a sitemap directly from your Laravel routes/web.php using [roumen/sitemap](https://github.com/Laravelium/laravel-sitemap).

```
Sitemap::add(Route::get('news', 'News@index'));
Sitemap::add('news/{article}', 'News@show'));
```

This works because, during install, you change the Route facade to point to a class of this package that adds a the fluent `sitemap` to Laravel `Route` instances. The `sitemap` method looks at the uri of the route and unpacks any model bindings it finds, fetching all public instances of those models and adding them to the sitemap.

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

[](#installation)

1. Run `require add bkwld/sitemap-from-routes`
2. Install [roumen/sitemap](https://github.com/Laravelium/laravel-sitemap) assets: `php artisan vendor:publish --provider="Roumen\Sitemap\SitemapServiceProvider"`
3. Add a route for the sitemap to your routes file: `Route::get('sitemap', '\Bkwld\SitemapFromRoutes\Controller@index')`.

#### Laravel &lt; 5.5

[](#laravel--55)

1. Add to `config.app` providers: `Bkwld\SitemapFromRoutes\ServiceProvider::class`
2. Add to `config.app` aliases: `'Sitemap' => Bkwld\SitemapFromRoutes\Facades::class`

Usage
-----

[](#usage)

Call `sitemap()` from any routes you want to add to the sitemap. For example:

```
Sitemap::add('news', 'News@index'));
Sitemap::add('news/{article}', 'News@show')->name('article'));
```

Dynamic route parameters must be named the same as the models they should resolve. So, in the above example, you must have an `App\Article` model.

By default, all instances of a model are added to the sitemap by substituting the id of the model into the uri. Thus, the example route would generate `news/1`, `news/2`, and so on.

#### Customize the query

[](#customize-the-query)

To customize which model instances should be added to the sitemap, specify a `forSitemap` scope on your model. You would do this to only add public records to the sitemap, for instance.

```
namespace App;
class Article {
    public function scopeForSitemap($query)
    {
        $query->where('public', 1);
    }
}

```

#### Customize the URL

[](#customize-the-url)

To customize the URL that is added to the sitemap for model instances, specify a `sitemapUrl` accessor on your model. You would do this if you use slugs in your URLs.

```
namespace App;
class Article {
    public function getSitemapUrlAttribute()
    {
        return route('article', $this->slug);
    }
}

```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

3168d ago

### Community

Maintainers

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

---

Top Contributors

[![weotch](https://avatars.githubusercontent.com/u/77567?v=4)](https://github.com/weotch "weotch (5 commits)")

### Embed Badge

![Health badge](/badges/bkwld-sitemap-from-routes/health.svg)

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

###  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)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[zonneplan/laravel-module-loader

Module loader for Laravel

24118.4k](/packages/zonneplan-laravel-module-loader)[kirschbaum-development/commentions

A package to allow you to create comments, tag users and more

12369.2k](/packages/kirschbaum-development-commentions)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)

PHPackages © 2026

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