Advanced Guides
Sitemap
Autoload comes bundled with an automatic sitemap generator. This will display any indexable Pages from
the CMS and output them to a /sitemap.xml
route within your Laravel application.
However, you may have other pages outside the Autoload-provided ones that you want to include in this sitemap. You may do so one of two ways;
-
By adding the
sitemap
middleware to your route(s) in yourroutes/web.php
file. -
By modifying the
sitemap_pages
configuration. This is an array of URLs with accompanying sitemap metadata.
Sitemap Middleware
You can add the sitemap
middleware to any route(s) in your routes/web.php
file to
automatically include them in the sitemap. You do not have control over the metadata of these pages however, so
no lastmod
or priority
will be set.
Example:
1<?php2 3use Illuminate\Support\Facades\Route;4 5Route::middleware(['sitemap'])->group(function () {6 Route::get('/', fn () => view('welcome'))->name('homepage');7 Route::view('/pricing', 'pricing')->name('pricing');8});
Sitemap Pages Configuration
You should provide at a minimum the slug
or URL of the page. You may optionally include a
lastmod
(last modified) date, and/or a priority
float to help resolve how important
the page is relative to the others.
Example:
1<?php 2 3// config/autoload.php 4return [ 5 'sitemap_pages' => [ 6 [ 7 'slug' => '/custom-route', 8 'lastmod' => '2023-01-01', 9 'priority' => '0.9',10 ],11 ]12];