Generate Dynamic sitemap in Laravel – onlinecode

Generate Dynamic sitemap in Laravel – onlinecode

In this post we will give you information about Generate Dynamic sitemap in Laravel – onlinecode. Hear we will give you detail about Generate Dynamic sitemap in Laravel – onlinecodeAnd how to use it also give you demo for it if it is necessary.

In this tutorial, i will tell about sitemap and what are the benefits of using sitemap in website and how can you create dynamic sitemap in Laravel using roumen/sitemap package.

There are so many benefits of using sitemap in your application, sitemap inform to search engine about any changes which is recently made in your website and using sitemap in website its become easier for search engine to rank your web pages.

Its good for your website to achieve better ranking on google.

Sitemap is just a simple file where all web pages of your website are listed to inform search engine about your site content.


roumen/sitemap Package Installation


Add following line of code in your composer to install packages in your application.

  1. "roumen/sitemap":"dev-master"
"roumen/sitemap": "dev-master"

Now run composer update command from command line.

Now add roumen service provider in followin path config/app.php

'RoumenSitemapSitemapServiceProvider',

Now add route for sitemap.

  1. Route::get('sitemap.xml',function(){
  2. $sitemap=app("sitemap");
  3. $articles= AppArticle::all();//fetch all articles to make url
  4. $sitemap->setCache('laravel.sitemap',60);
  5. $date=date('c');
  6. $priority=1.0;
  7. foreach($articlesas$key=>$article){
  8. $url=route('detail',[$article->slug]);
  9. $sitemap->add($url,$article->updated_at,$priority);
  10. }
  11. return$sitemap->render('xml');
  12. });
Route::get('sitemap.xml', function () {
   $sitemap = app("sitemap");      
   $articles = AppArticle::all() ; //fetch all articles to make url 
   $sitemap->setCache('laravel.sitemap',60);
   $date = date('c'); 
   $priority = 1.0;
   foreach($articles as $key=>$article){
      $url = route('detail',[$article->slug]) ;
      $sitemap->add($url,$article->updated_at,$priority) ;
    }
   return $sitemap->render('xml'); 
});

Laravel has so many packages to generate dynamic sitemap for your website, i have used one of them which is much easier to generate dynamic sitemap.

Hope this code and post will helped you for implement Generate Dynamic sitemap in Laravel – onlinecode. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

22  +    =  32

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US