|
|
#### Example: How to create dynamic sitemap
|
|
|
|
|
|
```php
|
|
|
Route::get('sitemap', function(){
|
|
|
|
|
|
// create new sitemap object
|
|
|
$sitemap = App::make("sitemap");
|
|
|
|
|
|
// set cache (key (string), duration in minutes (Carbon|Datetime|int), turn on/off (boolean))
|
|
|
// by default cache is disabled
|
|
|
$sitemap->setCache('laravel.sitemap', 3600);
|
|
|
|
|
|
// add item to the sitemap (url, date, priority, freq)
|
|
|
$sitemap->add(URL::to(), '2012-08-25T20:10:00+02:00', '1.0', 'daily');
|
|
|
$sitemap->add(URL::to('page'), '2012-08-26T12:30:00+02:00', '0.9', 'monthly');
|
|
|
|
|
|
// get all posts from db
|
|
|
$posts = DB::table('posts')->orderBy('created_at', 'desc')->get();
|
|
|
|
|
|
// add every post to the sitemap
|
|
|
foreach ($posts as $post)
|
|
|
{
|
|
|
$sitemap->add($post->slug, $post->modified, $post->priority, $post->freq);
|
|
|
}
|
|
|
|
|
|
// show your sitemap (options: 'xml' (default), 'html', 'txt', 'ror-rss', 'ror-rdf')
|
|
|
return $sitemap->render('xml');
|
|
|
|
|
|
}); |
|
|
\ No newline at end of file |