Automatically generate a sitemap in Laravel 5
freekmurze released a nice package that we can use to automatically generate a sitemap for our Laravel 5 applications.
This package can generate a sitemap without you having to add urls to it manually. This works by crawling your entire site.
use Spatie\Sitemap\SitemapGenerator;
SitemapGenerator::create('https://example.com')->writeToFile($path); You can also create your sitemap manually:
use Carbon\Carbon; use Spatie\Sitemap\Sitemap; use Spatie\Sitemap\Tags\Url; Sitemap::create() ->add(Url::create('/home') ->setLastModificationDate(Carbon::yesterday()) ->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY) ->setPriority(0.1)) ->add(...) ->writeToFile($path);
Link:
This post is submitted by our members. Submit a new post.
Tags: Tutorials Packages Sources Laravel 5 Laravel 5.1 Laravel 5.2 Laravel 5.3 Intermediate