Download the PHP package bkwld/sitemap-from-routes without Composer
On this page you can find all versions of the php package bkwld/sitemap-from-routes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bkwld/sitemap-from-routes
More information about bkwld/sitemap-from-routes
Files in bkwld/sitemap-from-routes
Package sitemap-from-routes
Short Description Generate a sitemap directly from your route definitions
License MIT
Informations about the package sitemap-from-routes
Sitemap from Routes
Generate a sitemap directly from your Laravel routes/web.php using roumen/sitemap.
This works because, during install, you change the Route facade to point to a class of this package that adds a the fluent sitemap
to Laravel Route
instances. The sitemap
method looks at the uri of the route and unpacks any model bindings it finds, fetching all public instances of those models and adding them to the sitemap.
Installation
- Run
require add bkwld/sitemap-from-routes
- Install roumen/sitemap assets:
php artisan vendor:publish --provider="Roumen\Sitemap\SitemapServiceProvider"
- Add a route for the sitemap to your routes file:
Route::get('sitemap', '\Bkwld\SitemapFromRoutes\Controller@index')
.
Laravel < 5.5
- Add to
config.app
providers:Bkwld\SitemapFromRoutes\ServiceProvider::class
- Add to
config.app
aliases:'Sitemap' => Bkwld\SitemapFromRoutes\Facades::class
Usage
Call sitemap()
from any routes you want to add to the sitemap. For example:
Dynamic route parameters must be named the same as the models they should resolve. So, in the above example, you must have an App\Article
model.
By default, all instances of a model are added to the sitemap by substituting the id of the model into the uri. Thus, the example route would generate news/1
, news/2
, and so on.
Customize the query
To customize which model instances should be added to the sitemap, specify a forSitemap
scope on your model. You would do this to only add public records to the sitemap, for instance.
Customize the URL
To customize the URL that is added to the sitemap for model instances, specify a sitemapUrl
accessor on your model. You would do this if you use slugs in your URLs.
All versions of sitemap-from-routes with dependencies
illuminate/database Version ^5.0
illuminate/routing Version ^5.0
illuminate/support Version ^5.0
roumen/sitemap Version ^2.6