Membuat Sitemap dengan laravel

  Umum

Route Web.php

Route::get('/rss.xml', 'akses@rss' ) ;

Controller Akses

public function rss () {
        
        $seo = DB::select("SELECT * FROM `seo` ORDER BY `seo`.`id_seo` ASC") ;

        

        return response(view('rss',['seo'=>$seo]))
        ->withHeaders([
            'Content-Type' => 'text/xml'
        ]);

View Rss.blade.php


   <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  
    <?php 
    $a = array(" ","/","%") ;
    $b = array("-","-","-") ;
    foreach ($seo as $dt ) {
    ?>
    <sitemap>
      <loc>{{url('/')}}/opendata/<?php echo $dt->id_seo ?>/<?php echo str_replace($a,$b,$dt->judul_seo) ?></loc>
   </sitemap>
<?php 
}
 ?>
   </sitemapindex>

LEAVE A COMMENT