Created
November 18, 2013 04:54
-
-
Save msurguy/7522748 to your computer and use it in GitHub Desktop.
Add sitemap to Laravel applications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
composer require roumen/sitemap | |
branch dev-master | |
add to app.php providers | |
'Roumen\Sitemap\SitemapServiceProvider', | |
then in your route do something like : | |
Route::get('sitemap', function(){ | |
$sitemap = App::make("sitemap"); | |
// set item's url, date, priority, freq | |
$sitemap->add(URL::to('/'), '2013-10-16T12:30:00+02:00', '1.0', 'daily'); | |
$sitemap->add(URL::to('resources'), '2012-11-16T12:30:00+02:00', '0.9', 'weekly'); | |
$snippets = Snippet::featured()->approved()->orderBy('created_at','desc')->get(); | |
foreach ($snippets as $snippet) | |
{ | |
$sitemap->add(url('snippets/featured/'.$snippet->slug), $snippet->updated_at, '0.5', 'weekly'); | |
} | |
$sitemap->add(URL::to('msurguy'), '2013-11-16T12:30:00+02:00', '0.8', 'weekly'); | |
$sitemap->add(URL::to('privacy'), '2013-11-16T12:30:00+02:00', '0.3', 'monthly'); | |
$sitemap->add(URL::to('about'), '2013-11-16T12:30:00+02:00', '0.3', 'monthly'); | |
$sitemap->add(URL::to('forms'), '2013-11-16T12:30:00+02:00', '0.6', 'weekly'); | |
$sitemap->add(URL::to('buttons'), '2013-11-16T12:30:00+02:00', '0.6', 'weekly'); | |
$sitemap->add(URL::to('tags'), '2013-11-16T12:30:00+02:00', '0.6', 'weekly'); | |
// show your sitemap (options: 'xml' (default), 'html', 'txt', 'ror-rss', 'ror-rdf') | |
return $sitemap->render('xml'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment