Create Sitemap XML in Laravel 8

Divi WordPress Theme

You will learn create sitemap in laravel. This tutorial will give you simple example of sitemap generator in laravel.

Simply step by step laravel sitemap example Here you will learn sitemap.xml in laravel. So, let’s follow few step to create example of sitemap in laravel.

Google gives the size of the site as one of the reasons why this is possible and need for a sitemap, Your website has too many pages that are not linked to each other or are isolated.

This means they are not referencing each other and by listing these files in a sitemap decreases the chance of Google not overlooking these pages, You will follow bellow step by step to create sitemap in your laravel app.

The Most Customizable WordPress Theme – The7

Step 1 : Create Route

Route::get('/sitemap.xml', 'SiteMapController@index');

Step 2 : Create Controller and Method


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Post;

class SiteMapController extends Controller
    public function index()
	  $posts= Post::latest()->get();
	  return response()->view('sitemap.index', [
	      'posts' => $posts,
	  ])->header('Content-Type', 'text/xml');


Step 3 : Create View File

<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>

<urlset xmlns="">
    @foreach ($posts as $post)
            <loc>{{ $post->title }}</loc>
            <lastmod>{{ $post->created_at }}</lastmod>

Step 4 : Run Your Application

php artisan serve

Step 5 : Open following link

You can check and confirm this. if have any problem please contact me.

thank you for follow this tutorial…

Khandoker Hirok

I'm an expert web developer over 6 years experience. I can fix bugs, customize and makes website and Software as per your requirements with Wordpress, PHP, Laravel and Codeigniter. My Fiverr:

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button