Download the PHP package otas/sitemap without Composer
On this page you can find all versions of the php package otas/sitemap. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package sitemap
Short Description A laravel package to create and generate sitemaps
License MIT
Informations about the package sitemap
Otas Sitemap
A Laravel package to generate multilingual XML sitemaps with support for static pages, dynamic model-based URLs, translated slugs, and multi-segment path templates.
Table of Contents
- Requirements
- Installation
- Configuration
- Static Links
- Dynamic Links
- The SitemapContract
- Non-Translated Slugs (buildDefaultUrls)
- Translated Slugs (buildLocalizedUrls)
- Multi-Segment URLs
- Path Template Placeholders
- Generating the Sitemap
- Serving the Sitemap
- Artisan Commands
- Full Examples
- Generated XML Output
- License
Requirements
- PHP 8.1+
- Laravel 9.0+
Installation
Run the setup command to publish the configuration file:
Or publish the config manually:
Configuration
After publishing, the configuration file is located at config/sitemap.php.
Note: The package also reads
config('translatable.locales')to determine which locales to generate URLs for. Make sure this is configured in your application (e.g. via theastrotomic/laravel-translatablepackage).
Static Links
Define static pages directly in the config file. Each entry specifies its location, alternate locale variants, and priority.
Dynamic Links
Dynamic links are generated from Eloquent model records. Register your models in the config:
The SitemapContract
Every model must implement Otas\Sitemap\Contracts\SitemapContract:
Path Template Placeholders
The sitemapTranslatedSegments() method returns a path template per locale. Templates use :placeholder syntax for dynamic parts:
Reserved placeholder:
| Placeholder | Resolved by |
|---|---|
:modelIdentifier |
Automatically resolved from the translations table (buildLocalizedUrls only). For buildDefaultUrls, you must provide it via slugResolver. |
Custom placeholders (:categorySlug, :brandSlug, etc.) are resolved via the $slugResolver callback:
The $slugResolver receives only the model item and returns a flat [':placeholder' => 'value'] map. No locale logic is needed inside it — the locale-specific path structure is already defined in the template.
Non-Translated Slugs (buildDefaultUrls)
Use this when the model's slug is the same across all locales (e.g. offers, products).
Since the slug is the same, there's no automatic resolution of :modelIdentifier. You must provide ALL placeholders in the slugResolver.
Simple example — single segment:
Generated URLs for an offer with slug summer-sale:
Translated Slugs (buildLocalizedUrls)
Use this when the model's slug is different per locale (e.g. blog posts with translated titles/slugs).
The :modelIdentifier placeholder is automatically resolved to the translated value for each locale from the model's translations table.
Simple example — single segment:
Generated URLs for a blog with EN slug laravel-tips and AR slug نصائح-لارافل:
Multi-Segment URLs
For URLs with multiple dynamic parts, add custom placeholders to the template and provide a slugResolver.
Example: Offer with Category (non-translated)
URL structure: offers/{category}/{offer-slug}
Generated URLs for offer summer-sale in category electronics:
Example: Blog with Category (translated)
URL structure: blogs/{category}/{post-slug}
Generated URLs for blog with EN slug laravel-tips, AR slug نصائح-لارافل, in category tech:
Example: Product with Brand + Category (three levels)
URL structure: shop/{brand}/{category}/{product-slug}
Generated URLs for product macbook-pro, brand apple, category laptops:
Generating the Sitemap
Generate the sitemap XML file using the Artisan command:
The file is saved to the public disk at the path configured in sitemap.base_path + sitemaps/sitemap.xml. If a subdomain is configured, the filename becomes {subdomain}-sitemap.xml.
You can schedule this command in your app/Console/Kernel.php:
Serving the Sitemap
When load_routes is true (default), the package registers a route that serves the generated sitemap:
The route prefix is controlled by package_routes_prefix in the config.
To publish and customize the route file:
This copies the route file to your application's routes/ directory for full control.
Artisan Commands
| Command | Description |
|---|---|
php artisan setup:sitemap |
Publish the config file (with overwrite prompt if it already exists) |
php artisan app:generate-sitemap |
Generate the sitemap XML and save it to the public disk |
php artisan sitemap:publish-routes |
Publish the package route file to your application's routes/ directory |
Full Examples
Minimal Setup (Single Model, No Translations)
1. Config:
2. Model:
3. Generate:
Complete Setup (Static + Multiple Dynamic Models)
Config:
Models:
Generated XML Output
The generated sitemap follows the Sitemaps XML protocol with xhtml:link alternate tags for multilingual support:
License
Otas Sitemap is open-sourced software licensed under the MIT license.