Laravel sitemap is a robust and easy-to-use solution designed to automatically generate sitemaps for your Laravel application.
You can require the package and it's dependencies via composer:
composer require fuelviews/laravel-sitemap
You can manually publish the config file with:
php artisan vendor:publish --provider="Fuelviews\Sitemap\SitemapServiceProvider" --tag="sitemap-config"
You can also add your models directly by implementing the Spatie\Sitemap\Contracts\Sitemapable interface. You also need to define your post_model in the fv-sitemap.php config file.
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Contracts\Sitemapable;
use Spatie\Sitemap\Tags\Url;
class Post extends Model implements Sitemapable {
/**
* Convert the Post model instance into a sitemap URL entry.
*
* @return \Spatie\Sitemap\Tags\Url
*/
public function toSitemapUrl() {
$url = Url::create(url("{$this->id}"))
->setLastModificationDate($this->updated_at)
->setChangeFrequency('daily')
->setPriority(0.8);
return $url;
}
}
You can generate the sitemap with:
php artisan sitemap:generate
You can link to the sitemap with:
route('sitemap')
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Fuelviews is a web development agency based in Portland, Maine. You'll find an overview of all our projects on our website.
The MIT License (MIT). Please see License File for more information.