How To Generate A Sitemap In Laravel 6/7/8/9

  • 19-09-2022
  • 936
  • Laravel 9
  • Haresh Chauhan

How To Generate A Sitemap In Laravel; Using composer require laravelium/sitemap we will generate a sitemap for our site in this tutorial example, Sitemap is too much important while you are working on a public website and want to invite the public from search engine organic browser. While you need to be required to submit your site to any search engine you must need to submit the theme and a site map. Based on that site map the search engine will Crowle your site.

using Laravel sitemap generator composer we will generate a site map with an example, in this example, we will create a dynamic sitemap and also a static sitemap.

We will create an XML sitemap in this tutorial, I have also given a different version package composer you can choose from and install in your application. having ended this tutorial you will easy to generate a sitemap for your web application based on route names.


Install Composer

Use the below-suggested command in your terminal and install sitemap to generate composer package dependency in your laravel application. copy and paste this command into your project terminal.

composer require laravelium/sitemap

Version (Optional)

If you want to look at a specific version package installation in your application find the form here. and add in your composer JSON file.

For Laravel 8
"laravelium/sitemap": "8.*"
For Laravel 8 (development branch)
"laravelium/sitemap": "8.x-dev"
For Laravel 7
"laravelium/sitemap": "7.*"
For Laravel 7 (development branch)
"laravelium/sitemap": "7.x-dev"
For Laravel 6
"laravelium/sitemap": "6.*"
For Laravel 6 (development branch)
"laravelium/sitemap": "6.x-dev"
For Laravel 5.8
"laravelium/sitemap": "3.1.*"
For Laravel 5.8 (development branch)
"laravelium/sitemap": "3.1.x-dev"
For Laravel 5.7
"laravelium/sitemap": "3.0.*"
For Laravel 5.7 (development branch)
"laravelium/sitemap": "3.0.x-dev"
For Laravel 5.6
"laravelium/sitemap": "2.8.*"
For Laravel 5.6 (development branch)
"laravelium/sitemap": "2.8.x-dev"
For Laravel 5.5
"laravelium/sitemap": "2.7.*"
For Laravel 5.5 (development branch)
"laravelium/sitemap": "2.7.x-dev"

Once you add the selected version to your application composer.json file, we need to install composer using the below provided command. So it will install only your application selected version only.

composer update

Once you install composer we meed to publish an asset config file for the sitemap to make it a stylish and pretty URL.

php artisan vendor:publish --provider="Laravelium\Sitemap\SitemapServiceProvider"

Dynamic Usage

You can use it in a loop with the collected database data, and for that, you need to follow the given example.

$sitemap = \App::make('sitemap');

$posts = Post::orderBy('id','desc')->where('status',1)->get();

foreach ($posts as $post) {



This sitemap will generate and store into your application root path, you can change the path according to your requirement.

Static Usage

You can also give your route with the static name, For example, you need to first create all the routes in your web.php file with the name.


Call the router with the given name in the sitemap argument as below given example.

$sitemap = \App::make('sitemap');



We always thanks to you for reading our blogs.


Dharmesh Chauhan

(Swapinfoway Founder)

Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us


Haresh Chauhan


We Are Also Recommending You :