https://github.com/Laravelium/laravel-sitemap
add the following to your composer.json
file :
"laravelium/sitemap": "3.0.*"
"laravelium/sitemap": "2.8.*"
"laravelium/sitemap": "2.7.*"
Publish needed assets (styles, views, config files) :
php artisan vendor:publish --provider="LaraveliumSitemapSitemapServiceProvider"
Note: Composer won't update them after composer update
, you'll need to do it manually!
public function sitemap(Request $request) { // create new sitemap object $sitemap = App::make("sitemap"); $sitemap->setCache('laravel.sitemap', 60); // get all posts from db $posts = News::where('audit_status', 0) ->orderBy('id', 'desc') ->get(); // add every post to the sitemap foreach ($posts as $post) { $sitemap->add(getenv('APP_URL')."/news/".$post->id.'.html', $post->created_at, 0.9, 'monthly'); } $sitemap->add(getenv('APP_URL')."/news.html", $post->created_at, 1, 'monthly'); $xml=$sitemap->render('xml'); // header('Content-Type: application/xml'); // header('Content-Disposition: attachment;filename="sitemap.xml"'); $path=public_path()."sitemap.xml"; $path=str_replace('\','/',$path); return file_put_contents($path,$xml->getContent()); }