PHP code example of kfoobar / laravel-sitemap

1. Go to this page and download the library: Download kfoobar/laravel-sitemap library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kfoobar / laravel-sitemap example snippets


use KFoobar\Sitemap\Facades\Sitemap;

Sitemap::add('https://example.com', now(), 'default');
Sitemap::generate();

use KFoobar\Sitemap\SitemapFactory;

(new SitemapFactory)
    ->add('https://example.com')
    ->add('https://example.com/about')
    ->generate();

use KFoobar\Sitemap\SitemapFactory;

$sitemap = new SitemapFactory;

foreach (Post::all() as $post) {
    $url = route('posts.show', $post);
    $lastModified = $post->updated_at->toIso8601String();

    $sitemap->add($url, $lastModified);
}

$sitemap->generate();
bash
php artisan vendor:publish --provider="KFoobar\Sitemap\SitemapServiceProvider"