<?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">
<url>
<loc>http://www.domain.com/sample-page</loc>
<changefreq>monthly</changefreq>
<priority>1.00</priority>
</url>
</urlset>
Bu üstteki temel bir sitemap.xml dosyası. Siz <url> kısmını sitenizdeki dinamik içerikleri foreach yaparak oluşturabilirsiniz. Mesela sitemap.blade.php isimli bir view oluşturun, SitemapController oluşturun, view'a içeriği gönderin.
Route::get('sitemap.xml', ['uses'=>'SitemapController@index']);
// SitemapController@index
public function index()
{
$posts = Post::all();
$pages = Page::active()->get();
$view = view('sitemap', compact('posts','pages'));
return response()->make($view, 200)->header('Content-Type', 'text/xml');
}
// sitemap.blade.php
<?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($posts as $post)
<url>
<loc>{{ url($post->slug) }}</loc>
<changefreq>monthly</changefreq>
<priority>1.00</priority>
</url>
@endforeach
@foreach($pages as $page)
<url>
<loc>{{ url($page->slug) }}</loc>
<changefreq>monthly</changefreq>
<priority>1.00</priority>
</url>
@endforeach
</urlset>
gibi. Tabi sitemap.xml dosyasını fiziksel olarak oluşturmak isteyeceksinizdir ya da cache kullanmak isteyeceksinizdir, bunları da yapacağınız sisteme ekleyebilirsiniz.
Hazır paket kullanmak isterseniz:
https://github.com/RoumenDamianoff/laravel-sitemap
Milyonlarca kayıttan sitemap oluşturmak için (üstteki bunun için ideal değil):
https://github.com/o/sitemap-php