Laravel simple XML sitemap

Submitted by haruncpi - 4 years ago

Make a sitemap for your laravel blog site. Posted on https://bit.ly/36v9Elp

//make view route
Route::view('sitemap.xml','sitemap');

//sitemap.blade.php
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    @foreach (\App\Post::all() as $post)
        <url>
            <loc>{{url('/')}}/{{ $post->slug_url }}</loc>
            <lastmod>{{ gmdate('Y-m-d\TH:i:s\Z',strtotime($post->updated_at)) }}</lastmod>
            <changefreq>daily</changefreq>
            <priority>0.6</priority>
        </url>
    @endforeach
</urlset>

// more detail: https://bit.ly/36v9Elp