PHPackages                             dividing-zero/laravel-dynamic-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. dividing-zero/laravel-dynamic-sitemap

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

dividing-zero/laravel-dynamic-sitemap
=====================================

Automatically generate dynamic sitemaps at runtime using Eloquent Models in Laravel.

v1.1.2(2mo ago)0133↓100%MITPHP

Since Jul 18Pushed 2mo agoCompare

[ Source](https://github.com/dividing-zero/laravel-dynamic-sitemap)[ Packagist](https://packagist.org/packages/dividing-zero/laravel-dynamic-sitemap)[ RSS](/packages/dividing-zero-laravel-dynamic-sitemap/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (8)Used By (0)

Laravel Dynamic Sitemap
=======================

[](#laravel-dynamic-sitemap)

Automatically generate dynamic sitemaps at runtime using Eloquent Models in Laravel.

Easily include records for specific Eloquent models by using the `Sitemappable` trait, and specific routes using the `sitemappable` middleware.

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

[](#installation)

```
composer require dividing-zero/laravel-dynamic-sitemap
```

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

[](#configuration)

Publish the config file:

```
php artisan vendor:publish --provider="DividingZero\LaravelDynamicSitemap\SitemapServiceProvider" --tag="config"
```

Edit `config/sitemap.php` to specify models and settings:

```
return [

    /*
    |--------------------------------------------------------------------------
    | Models
    |--------------------------------------------------------------------------
    |
    | List fully qualified model class names to include in the sitemap.
    | These models should implement the `Sitemappable` trait.
    |
    | E.g. App\Models\Blog::class
    |
    */
    'models' => [

    ],

    /*
    |--------------------------------------------------------------------------
    | Default Modified Date
    |--------------------------------------------------------------------------
    |
    | The default modified date to use when a model does not define a `getModifiedDate` method.
    | This will also be used for any routes which are manually included via middleware, so it is recommended to set it to the last time the site was updated.
    |
    | E.g. 2025-01-01
    |
    */
    'default_modified_date' => '2025-01-01', // Use null to default to now()

    /*
    |--------------------------------------------------------------------------
    | Default Change Frequency
    |--------------------------------------------------------------------------
    |
    | The default change frequency to use when a model does not define a `getChangeFrequency` method.
    | This will also be used for any routes which are manually included via middleware, so a reasonable default such as 'monthly' is recommended.

    | Options: always, hourly, daily, weekly, monthly, yearly, never
    |
    */
    'default_change_frequency' => 'monthly',

    /*
    |--------------------------------------------------------------------------
    | Default Priority
    |--------------------------------------------------------------------------
    |
    | The default priority to use when a model does not define a `getPriority` method.
    | This will also be used for any routes which are manually included via middleware.
    |
    | Priority values range from 0.0 to 1.0, where 1.0 is the highest priority.
    | A value of 0.5 is a common default.
    |
    |*/
    'default_priority' => 0.5,

    /*
    |--------------------------------------------------------------------------
    | Cache Lifetime
    |--------------------------------------------------------------------------
    |
    | The number of seconds to cache the generated sitemap.
    | This helps improve performance by avoiding frequent regeneration.
    | Set to 0 to disable caching.
    |
    |*/
    'cache_lifetime' => 60

];
```

Sitemappable Trait
------------------

[](#sitemappable-trait)

To include records for specific models in the sitemap, add the fully qualified class name to the `dynamic-sitemap.models` configuration, and inherit the `sitemappable` trait on the corresponding model.

```
use DividingZero\LaravelDynamicSitemap\Traits\Sitemappable;

class Post extends Model
{
    use Sitemappable;

    // Required overrides

    /**
     * Define the sitemap URL for this model instance.
     *
     * @return string
     */
    public function getSitemapUrl(): string;

    // Optional overrides

    /**
     * Get the last modification date for the sitemap entry.
     *
     * @return \Carbon\Carbon
     */
    public function getSitemapModifiedDate(): Carbon
    {
        return $this->updated_at ?? Carbon::parse(config('sitemap.default_modified_date'));
    }

    /**
     * Get the change frequency for the sitemap entry.
     *
     * @return string (e.g., 'daily', 'weekly')
     */
    public function getSitemapChangeFreqency(): string
    {
        // Use config default if not overridden
        return config('sitemap.default_change_frequency');
    }

    /**
     * Get the priority for the sitemap entry.
     *
     * @return float
     */
    public function getSitemapPriority(): float
    {
        // Use config default if not overridden
        return config('sitemap.default_priority');
    }

    /**
     * Scope a query to only include records that should be in the sitemap.
     * Returns unscoped query with all records by default.
     *
     * @param  \Illuminate\Database\Eloquent\Builder  $query
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeSitemapQuery($query)
    {
        return $query;
    }
}
```

Sitemappable Middleware
-----------------------

[](#sitemappable-middleware)

To include specific routes in the sitemap, add the `sitemappable` middleware to those routes:

```
Route::get('/about', 'PageController@about')->middleware('sitemappable');
```

*Note: If any route parameters exist they will be removed, since route parameters cannot be resolved automatically.*

Usage
-----

[](#usage)

Visit `/sitemap.xml` in your browser to view the generated sitemap.

Caching
-------

[](#caching)

The sitemap is cached for the duration specified in `cache_lifetime`. Set to `0` to disable caching (the sitemap will be regenerated on every request).

License
-------

[](#license)

MIT

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance85

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

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

Every ~36 days

Recently: every ~54 days

Total

7

Last Release

79d ago

### Community

Maintainers

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

---

Top Contributors

[![elanclarkson](https://avatars.githubusercontent.com/u/10159119?v=4)](https://github.com/elanclarkson "elanclarkson (11 commits)")

### Embed Badge

![Health badge](/badges/dividing-zero-laravel-dynamic-sitemap/health.svg)

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

PHPackages © 2026

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