1. Go to this page and download the library: Download mfonte/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/ */
mfonte / laravel-sitemap example snippets
use Carbon\Carbon;
use Mfonte\Sitemap\Sitemap;
use Mfonte\Sitemap\Tags\Url;
Sitemap::create()
->add(
Url::create('/home')
->setLastModificationDate(Carbon::yesterday())
->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY)
->setPriority(0.1)
->addImage('/path/to/image', 'A wonderful Caption')
->addNews('A long story short', 'en', Carbon::yesterday(), 'Sitemaps are this great!')
)
->add(...)
->writeToFile($path);
use Mfonte\Sitemap\Contracts\Sitemapable;
use Mfonte\Sitemap\Tags\Url;
class Post extends Model implements Sitemapable
{
public function toSitemapTag(): Url | string | array
{
return route('blog.post.show', $this);
}
}
use Mfonte\Sitemap\Sitemap;
Sitemap::create()
->add($post)
->add(Post::all());
use Mfonte\Sitemap\SitemapIndex;
SitemapIndex::create()
->add('/pages_sitemap.xml')
->add('/posts_sitemap.xml')
->writeToFile($sitemapIndexPath);
use Mfonte\Sitemap\SitemapIndex;
use Mfonte\Sitemap\Tags\Sitemap;
SitemapIndex::create()
->add('/pages_sitemap.xml')
->add(Sitemap::create('/posts_sitemap.xml')
->setLastModificationDate(Carbon::yesterday()))
->writeToFile($sitemapIndexPath);
use Carbon\Carbon;
use Mfonte\Sitemap\Sitemap;
use Mfonte\Sitemap\Tags\Url;
$sitemapStream = Sitemap::create()
->add(
Url::create('/home')
->setLastModificationDate(Carbon::yesterday())
->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY)
->setPriority(0.1)
->addImage('/path/to/image', 'A wonderful Caption')
->addNews('A long story short', 'en', Carbon::yesterday(), 'Sitemaps are this great!')
)
->add(...)
->render(true); // note the "true" on the render() method.
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.