ultrono/laravel-sitemap

PHP 8 sitemap generator for Laravel 8, 9, 10 and 11

9.4.0 2024-03-23 09:02 UTC

README

Packagist Version run-tests PHP ^8.0

Laravel Sitemap

This is a Laravel 8, 9, 10 and 11 only fork of Laravelium/laravel-sitemap. The original repository has been abandoned.

PHP ^8.0 is required.

Installation

If laravelium/sitemap is already part of the project:

composer remove laravelium/sitemap

Then run:

composer require ultrono/laravel-sitemap
php artisan vendor:publish --provider="Ultrono\Sitemap\SitemapServiceProvider"

Generate a simple sitemap

Route::get('mysitemap', function() {
    $sitemap = resolve("sitemap");

    $sitemap->add(URL::to(), '2012-08-25T20:10:00+02:00', '1.0', 'daily');
    $sitemap->add(URL::to('page'), '2012-08-26T12:30:00+02:00', '0.9', 'monthly');

    $posts = DB::table('posts')->orderBy('created_at', 'desc')->get();

    foreach ($posts as $post) {
        $sitemap->add($post->slug, $post->modified, $post->priority, $post->freq);
    }

    // generate (format, filename)
    // sitemap.xml is stored within the public folder
    $sitemap->store('xml', 'sitemap');
});

Examples

and more in the Wiki.