 
Route::get('sitemap.xml', 'SitemapController@index')->name('sitemapxml'); 
Now you can create SitemapController.php with artisan command php artisan make:controller SitemapController public function index() {
    $page = Post::where('status', '=', 1)->get();
    return response()->view('sitemap_xml', ['page' => $page])->header('Content-Type', 'text/xml');
}
Now please create a view file in  <?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
<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">
@foreach ($page as $post)
<url>
<loc>{{ url($post->page_slug) }}</loc>
<lastmod>{{ $post->updated_at->tz('UTC')->toAtomString() }}</lastmod>
<priority>0.9</priority>
</url>
@endforeach
</urlset>
We are Recommending you:
- Custom 404 Page In Laravel 8
- Laravel 7 multi auth login
- How to generate dynamic real time sitemap.xml file in Laravel 8
- Laravel Command List
- Laravel's .htaccess to remove "public" from URL
- How to use soft delete in Laravel?
- How to change timezone in laravel 8
- How to Secure Your Laravel App: Beyond SSL Basics
- Laravel 8 multi auth login
 
                  Master Your Time with the 80/20 Rule: A...
 
                  Get Control of Your Time: 6 Easy Ways...
 
                  India’s startup space is booming in 2025....
 
                  India breeds dreamers who build empires....
 
                  Introduction: Why Security Matters Laravel...
 
                  Warning Signs You’re Losing Time We all...
 
                  User experience (UX) plays a vital role in...
 
                  WordPress powers millions of websites, and...
 
                  Convert a PEM File to PPK | Easy Guide for...