PHP code example of gyvex-com / laravel-macro-sitemap
1. Go to this page and download the library: Download gyvex-com/laravel-macro-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/ */
gyvex-com / laravel-macro-sitemap example snippets
use GyvexCom\LaravelMacroSitemap\Support\Enums\ChangeFrequency;
Route::get('/contact', ContactController::class)
->name('contact')
->sitemap()
->changefreq(ChangeFrequency::WEEKLY)
->priority('0.8');
namespace App\Sitemap\Templates;
use App\Models\Post;
use Illuminate\Routing\Route;
use GyvexCom\LaravelMacroSitemap\Sitemap\Item\Url;
use GyvexCom\LaravelMacroSitemap\Sitemap\Template;
class PostTemplate extends Template
{
public function generate(Route $route): iterable
{
yield from $this->urlsFromModel(Post::class, $route, function (Post $post, Route $route) {
return Url::make(route($route->getName(), ['slug' => $post->slug]))
->lastmod($post->updated_at)
->priority(0.6);
});
}
}
use GyvexCom\LaravelMacroSitemap\Sitemap\SitemapIndex;
$sitemapIndex = SitemapIndex::make('https://example.com/sitemap-pages.xml')
->add('https://example.com/sitemap-posts.xml');