Posted inTechnology / Laravel / Mysql / Mysqli / Programming / SEO

Automatically Laravel Create dynamic generate sitemap

Automatically Laravel Create dynamic generate sitemap

In this Post We Will Explain About is Automatically Laravel Create dynamic generate sitemapBuilding a Search Engine Friendly Sitemap XML with Laravel With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Example

In this post we will show you Best way to implement Generate a sitemap -> use Blade for xml-document, hear for Automatically generate a sitemap in Laravel 5with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Therefore, let’s follow some source code following Phase as well as use it. i provide just two Phase one for installing packages as well as second one for some example of sitemap generate.Laravel 5 generate sitemap using live24u/sitemap package Example

Step 1: Installation Package

first We have to fire following commas well as on We terminal as well as get latest version of “live24u/sitemap” package.

composer require live24u/sitemap

Add ServiceProvider

Ok, And then open config/app.php file as well as add service provider of That package.

'providers' => [

	....some code

	'Roumen\Sitemap\SitemapServiceProvider',

]

Publish Config File

following commas well as through We may create publish config file of “live24u/sitemap” package. after fire That commas well as We may see one file app/config/sitemap.php as well as We may change We own setting.

php artisan vendor:publish --provider="Roumen\Sitemap\SitemapServiceProvider"

Step 2: Example With Route

In Last Phase i provide example of how to generate sitmap. so first open app/Http/routes.php as well as add following route.

app/Http/routes.php

Route::get('sitemap', function(){

    /*Devloped by Pakainfo.com create new sitemap object */

    $sitemap = App::make("sitemap");

    

    /*Devloped by Pakainfo.com add item to the some sitemap parameters(url, date, priority, freq) */

    $sitemap->add(URL::to('/'), '2020-08-25T20:10:00+02:00', '1.0', 'daily');

    
 

    $datamsts = DB::table('datamst')

                ->select('datamst.*'

                    ,'datamst.title as datamstTitle','datamst.slug as datamstSlug'

                    ,'datamst_image.image as image','datamst.updated_at as datamstUpdated_at')

                    ->join('datamst_image','datamst_image.datamst_id','=','datamst.id')

                    ->orderBy('created_at','desc')

                    ->groupBy('datamst.id')

                    ->get();

    

    $data_slug_results = array();

    if(!empty($datamsts)){

        foreach ($datamsts as $key => $value) {

            $data_slug_results[$value->id]['id'] = $value->id;

            $data_slug_results[$value->id]['slug'] = $value->datamstSlug;

            $data_slug_results[$value->id]['datamstTitle'] = $value->datamstTitle;

            $data_slug_results[$value->id]['datamstUpdated_at'] = $value->datamstUpdated_at;

            $data_slug_results[$value->id]['image'][] = $value->image;

        }

    }

    

     /*Devloped by Pakainfo.com add every datamst to the sitemap */

     foreach ($data_slug_results as $key=>$value)

     {

        $images = array();

        foreach ($value['image'] as $key2 => $value2) {

            $images[] = array(

                'url' => URL::to('/')."/uploadImages/datamst/".$value2,

                'title' => $value['slug'],

                'caption' => $value['datamstTitle']

            );    

        }

        $sitemap->add(URL::route('front.datamst',$value['slug']), $value['datamstUpdated_at'], '1.0', 'daily', $images);

    }

    

    /* Devloped by Pakainfo.com show We are sitemap like as a (options: 'xml' (default), 'html', 'txt', 'ror-rss', 'ror-rdf') */

    return $sitemap->render('xml');

});

And then We may open sitemap route url as well as check output, it shell be like some preview. we may also get more some information of That data package from here : Wiki

Example

I hope you have Got What is Building a Search Engine Friendly Sitemap XML with Laravel And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

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

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype