I use the spatie/laravel-sitemap library This is my code
Route::get('/sitemap', function () {
$sitemap = \Spatie\Sitemap\Sitemap::create()
->add(\Spatie\Sitemap\Tags\Url::create('/index')->setPriority(1.0))
->add(\Spatie\Sitemap\Tags\Url::create('/contact')->setPriority(0.8))
->add(\Spatie\Sitemap\Tags\Url::create('/portfolios')->setPriority(0.7))
->add(\Spatie\Sitemap\Tags\Url::create('/services')->setPriority(0.6))
->add(\Spatie\Sitemap\Tags\Url::create('/about')->setPriority(0.5));
\App\Models\Post::all()->each(function (\App\Models\Post $post) use ($sitemap) {
$url = \Spatie\Sitemap\Tags\Url::create("/posts/{$post->slug}")
->setLastModificationDate($post->updated_at)
->setChangeFrequency(\Spatie\Sitemap\Tags\Url::CHANGE_FREQUENCY_YEARLY)
->setPriority(0.1);
$sitemap->add($url);
});
$sitemap->writeToFile(public_path('sitemap.xml'));
return 'Generated';
});
The problem is that the two features setChangeFrequency and setPriority are not added to the site map
please guide me
Problem in spatie/laravel-sitemap library
Chagefreq and priority tags was removed in release 7.2.1. You can read more here. If you want to use this tags, remove current version of spatie/laravel-sitemap library and install previous - 7.2.0. After that clear view cache in Laravel application.
composer remove spatie/laravel-sitemap
composer require spatie/laravel-sitemap:7.2.0
php artisan view:clear
Have a nice day!