bkwld/sitemap-from-routes
Composer 安装命令:
composer require bkwld/sitemap-from-routes
包简介
Generate a sitemap directly from your route definitions
README 文档
README
Generate a sitemap directly from your Laravel routes/web.php using roumen/sitemap.
Sitemap::add(Route::get('news', 'News@index')); Sitemap::add('news/{article}', 'News@show'));
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.appproviders:Bkwld\SitemapFromRoutes\ServiceProvider::class - Add to
config.appaliases:'Sitemap' => Bkwld\SitemapFromRoutes\Facades::class
Usage
Call sitemap() from any routes you want to add to the sitemap. For example:
Sitemap::add('news', 'News@index')); Sitemap::add('news/{article}', 'News@show')->name('article'));
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.
namespace App;
class Article {
public function scopeForSitemap($query)
{
$query->where('public', 1);
}
}
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.
namespace App;
class Article {
public function getSitemapUrlAttribute()
{
return route('article', $this->slug);
}
}
bkwld/sitemap-from-routes 适用场景与选型建议
bkwld/sitemap-from-routes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 310 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 09 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 bkwld/sitemap-from-routes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bkwld/sitemap-from-routes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 310
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-09-08