spatie/laravel-sitemap
Generate XML sitemaps for Laravel by crawling your site or building them manually. Add extra URLs, set last-modified dates, and include models via a simple interface. Write sitemaps to disk with a fluent, developer-friendly API.
You can sort the URLs in your sitemap alphabetically using the sort() method. This is useful for maintaining a consistent order in your sitemap files.
use Spatie\Sitemap\Sitemap;
$sitemap = Sitemap::create()
->add('/zoo')
->add('/blog')
->add('/about')
->add('/contact')
->sort();
The sort() method will arrange all URLs in alphabetical order.
The sort operation is case-sensitive, with uppercase letters sorted before lowercase letters. For example:
$sitemap = Sitemap::create()
->add('/Zebra')
->add('/apple')
->add('/BANANA')
->sort();
// Results in order: /BANANA, /Zebra, /apple
The sort() method returns the sitemap instance, allowing you to chain it with other methods:
$sitemap = Sitemap::create()
->add('/page1')
->add('/page3')
->add('/page2')
->sort()
->writeToFile(public_path('sitemap.xml'));
How can I help you explore Laravel packages today?