use Carbon\Carbon;
use FinalStrike\Sitemap\Sitemap;
use FinalStrike\Sitemap\Tags\Url;
Sitemap::create()
->add(Url::create('/home')
->setLastModificationDate(Carbon::yesterday())
->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY)
->setPriority(0.1))
->add(...)
->writeToFile($path);
First, install the package via composer:
composer require finalstrike/sitemap
The package will automatically register itself.
You can override the views. First publish the configuration:
php artisan vendor:publish --provider="FinalStrike\Sitemap\SitemapServiceProvider"
use Carbon\Carbon;
Sitemap::create()
->add('/page1')
->add('/page2')
->add(Url::create('/page3')->setLastModificationDate(Carbon::create('2016', '1', '1')))
->writeToFile($sitemapPath);
You can create a sitemap index:
use FinalStrike\Sitemap\SitemapIndex;
SitemapIndex::create()
->add('/pages_sitemap.xml')
->add('/posts_sitemap.xml')
->writeToFile($sitemapIndexPath);
You can pass a FinalStrike\Sitemap\Tags\Sitemap
object to manually set the lastModificationDate
property.
use FinalStrike\Sitemap\SitemapIndex;
use FinalStrike\Sitemap\Tags\Sitemap;
SitemapIndex::create()
->add('/pages_sitemap.xml')
->add(Sitemap::create('/posts_sitemap.xml')
->setLastModificationDate(Carbon::yesterday()))
->writeToFile($sitemapIndexPath);
the generated sitemap index will look similar to this:
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>http://www.example.com/pages_sitemap.xml</loc>
<lastmod>2016-01-01T00:00:00+00:00</lastmod>
</sitemap>
<sitemap>
<loc>http://www.example.com/posts_sitemap.xml</loc>
<lastmod>2015-12-31T00:00:00+00:00</lastmod>
</sitemap>
</sitemapindex>
The MIT License (MIT). Please see License File for more information.