Generator to easiely making sitemap data

1.0.1 2021-10-25 08:38 UTC

This package is auto-updated.

Last update: 2024-06-25 14:34:42 UTC


Sitemap Generator

Gitlab pipeline status


Generating sitemap.xml file means either writing raw xml or stocking data then loop on it. This generator allows you to generate urls data to show in your file.


I created it when i had to generate a sitemap.xml file from one of my Laravel projects. Originally made to work only with Laravel, I finaly modified it to works on every php projects. In addition, Blade the template engine provided by Laravel take any array as a collection so, i don't have to create any adapted package.


composer require nolikein/sitemap-generator ^1.0.0


Example with Php from sracth

use Nolikein\SitemapGenerator\SitemapFactory;

    $generator = new SitemapFactory();
        ->addRoute('', new Datetime('now'), 'always', 1)
    $routes = $generator->getRoutes();

Example with Laravel

Here an example with Laravel 8 :

use Nolikein\SitemapGenerator\SitemapFactory;

    $generator = new SitemapFactory();
        ->addRoute(route('welcome'), now(), 'always', 1)
    return response()
            ->view('frontoffice.sitemap', [
                'routes' => $generator->getRoutes()
            ->header('Content-Type', 'application/xml');

## Showing the result into a sitemap file (blade example)

{{-- @php echo '<?xml version="1.0" encoding="UTF-8"?>' @endphp --}}
<urlset xmlns="">
    @foreach ($routes as $route)
            <loc>{{ $route->getUrl() }}</loc>
            <lastmod>{{ $route->getLastmodification()->format('Y-m-d') }}</lastmod>
            <changefreq>{{ $route->getFrequency() }}</changefreq>
            <priority>{{ $route->getPriority() }}</priority>