How to Create Dynamic Sitemap in Laravel Framework?

“Generate Dynamic Sitemap in Laravel Framework, Create Dynamic Sitemap in Laravel 5.7,Laravel 6.0, Create Dynamic Sitemap in Laravel 5.8,Create Dynamic Sitemap in Laravel 5.6,Create Dynamic Sitemap in Laravel 5.4,Create Dynamic Sitemap in Laravel 5.3,Create Dynamic Sitemap in Laravel 5.2”

Hello friends This is a new blog. This blog will tell you how to Generate Dynamic Sitemap in the Laravel Framework. Today, through this tutorial you will be told step by step.

First of all I will tell you why a sitemap for any website is created. The use of sitemap basically gives information about how many links are being created in your website. Google indexes the entire link by the sitemap. sitemap which is generated. They are generated in XML form.

Step 1:-

routes/web.php

Route::get('sitemap.xml', function() {
$view = view('sitemap');
return Response::make($view)->header('Content-Type', 'text/xml');
});

You will create a blade file with the name of the sitemap (sitemap.blade.php) and after that you will write your php code. For this you can see below.

Step 2:-

resources/views/sitemap.blade.php

sitemap.blade.php

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<?php
$brands=DB::table('forum_brands')->get();
foreach ($brands as $key => $value) {
$brandss = $brands[$key]->brands;
?>
<url>
<loc>http://www.routertechnicalsupport.com/brands/{{$brandss}}</loc>
<lastmod>2017-02-06T12:37:12+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>0.80</priority>
</url>
<?php } ?>
</urlset>