The Laravel Sitemap package by Fuelviews is a robust and easy-to-use solution designed to automatically generate sitemaps for your Laravel application. This package simplifies the process of creating dynamic sitemaps, ensuring that search engines can effortlessly discover and index your website's pages. Whether you're managing a small blog or a large e-commerce platform, our Laravel Sitemap package seamlessly integrates with your project, enhancing SEO performance and visibility.
You can require the package and it's dependencies via composer:
composer require fuelviews/laravel-sitemap
You can install the package with:
php artisan sitemap:install
You can manually publish the config file with:
php artisan vendor:publish --provider="Fuelviews\Sitemap\SitemapServiceProvider" --tag="laravel-sitemap-config"
This is the contents of the published config file:
return [
/**
* Specifies the default filesystem disk that should be used.
* The 'public_path' disk is typically used for files that need to be publicly accessible to users.
* This setting can influence where files, such as generated sitemaps, are stored by default.
*/
'disk' => 'public',
/**
* Determines whether the index page should be excluded from the sitemap.
* Setting this to `true` will exclude the index page, `false` will include it.
*/
'exclude_index' => true,
/**
* Controls whether redirect URLs should be excluded from the sitemap.
* When set to `true`, all redirects are excluded to ensure the sitemap only contains direct links.
*/
'exclude_redirects' => true,
/**
* An array of route names to be excluded from the sitemap.
* Useful for excluding specific pages that should not be discoverable via search engines.
*/
'exclude_route_names' => [
],
/**
* Specifies paths that should be excluded from the sitemap.
* Any routes starting with these paths will not be included in the sitemap, enhancing control over the sitemap contents.
*/
'exclude_paths' => [
],
/**
* An array of full URLs to be excluded from the sitemap.
* This allows for fine-grained exclusion of specific pages, such as sitemap files or any other URLs not suitable for search engine indexing.
*/
'exclude_urls' => [
'/sitemap.xml',
'/pages_sitemap.xml',
'/posts_sitemap.xml',
],
];
You can also add your models directly by implementing the \Spatie\Sitemap\Contracts\Sitemapable interface.
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
To access the sitemap, navigate to your application's URL and append /sitemap.xml to it.
For example, if your application is hosted at http://www.example.com, the sitemap can be found at http://www.example.com/sitemap.xml.
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.