Creating sitemap on laravel 4.2

Needed something to generate sitemap.xml using laravel and founded this


add to composer.php

"roumen/sitemap": "dev-master#dd8d820580a48394bae67c738e3f0ec4cc1d8793"

add to app.php


On your route.php

Route::get('sitemap', function(){
    // create new sitemap object
    $sitemap = App::make("sitemap");
    // set cache (key (string), duration in minutes (Carbon|Datetime|int), turn on/off (boolean))
    // by default cache is disabled
    //$sitemap->setCache('laravel.sitemap', 3600);

    // check if there is cached sitemap and build new only if is not
    /*if (!$sitemap->isCached())
         // add item to the sitemap (url, date, priority, freq)
         $sitemap->add(URL::to('/'), '2015-03-31T20:10:00+02:00', '1.0', 'daily');
         $sitemap->add(URL::to('tentangkami'), '2015-03-31T20:10:00+02:00', '0.9', 'monthly');
         $sitemap->add(URL::to('jadwal'), '2015-03-31T20:10:00+02:00', '0.9', 'monthly');
         $sitemap->add(URL::to('formulir'), '2015-03-31T20:10:00+02:00', '0.9', 'monthly');
         $sitemap->add(URL::to('hubungikami'), '2015-03-31T20:10:00+02:00', '0.9', 'monthly');
         //$sitemap->add(URL::to('page'), '2015-03-31T12:30:00+02:00', '0.9', 'monthly');

         // get all posts from db
         $posts = DB::table('blog')->orderBy('created_at', 'desc')->get();
         // add every post to the sitemap
         foreach ($posts as $post)
            $sitemap->add(Url::to('blog/'.$post->id.'/'.urlformat($post->title)), $post->updated_at , '0.9', 'weekly');

         // get all posts from db
         $posts1 = DB::table('gallery')->orderBy('created_at', 'desc')->get();
         // add every post to the sitemap
         foreach ($posts1 as $post)
              if (!empty($post->title))
                 $sitemap->add(Url::to('gallery/'.$post->id.'/'.urlformat($post->title)), $post->updated_at,  '0.9', 'weekly');

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


There was an error on generating xml

so I went to src/views/xml.blade.php
took out the first line and it worked

{!! '<'.'?'.'xml version="1.0" encoding="UTF-8"?>' !!}