fredyounan
1/29/2015 - 3:42 AM

laravel_xml_sitemap.php

// XML sitemap - requires this package: https://github.com/RoumenDamianoff/laravel-sitemap

Route::get('/xml-sitemap', array('as' => 'xml-sitemap', function(){

	$sitemap = App::make("sitemap");
	$dt = new DateTime();
	$dt = $dt->format(DateTime::ISO8601);

	$routes = Route::getRoutes();

	foreach ( $routes as $route )
	{
		$uri = $route->getURI();
		$path = $route->getPath();
		if ( ! preg_match('/xml-sitemap/', $path) )
		{
			$priority = ( preg_match('/^\//', $uri ) ) ? '1.0' : '0.9';
			$sitemap->add(URL::to($path), $dt, $priority, 'daily');
		}
	}

	// show your sitemap (options: 'xml' (default), 'html', 'txt', 'ror-rss', 'ror-rdf')
	return $sitemap->render('xml');

}));