hantu / sitemap
此包的最新版本(0.0.13)没有可用的许可信息。
Laravel 应用程序的 Sitemap
0.0.13
2019-06-30 09:02 UTC
Requires
- laravelcollective/html: ^5.8.0
This package is not auto-updated.
Last update: 2024-10-02 10:12:15 UTC
README
这是一个用于实现网站地图功能的 Laravel 测试包。
安装
composer require hantu/sitemap
更新 composer 后,将服务提供者添加到 config/app.php 中的 providers 数组中
Hantu\Sitemap\Providers\SiteMapServiceProvider::class
发布迁移和 CSS 样式
php artisan vendor:publish --tag=sitemap-migrations
php artisan vendor:publish --tag=sitemap-styles
可选功能
// prefix to configurate url to sitemap
'route_prefix' => env('BACKEND_URL', 'backend'),
// config for route prefix
'route_as' => 'backend.',
//driver for sitemap.xml
'filesystem_driver' => 'public',
// routes middleware
'route_middleware' => ['web'],
/**
* to use feature your model have to use trait Sitemap
* or release method getUrls where you return array with prepared URL's for siteMap
* and add class to this array as in the example below
*/
'dynamic_url_classes' => [
\App\Models\Pages::class
],
// Route names for siteMap
'static_routes' => [
],
如何使用?
<?php
class Pages extends Model
{
use Sitemap;
}
您可以指定列名和基础 URL。只需在您的模型中添加参数即可
public $columnName = 'alias';
public $baseUrl = null;
或覆盖方法
public function getUrls() : array
{
return $urls;
}
public function makeUrl($baseUrl, $item) : string
{
return $url
}
要上传 URL 到数据库,您可以使用链接旁的界面按钮:{yourAppUrl}/backend/sitemap 或使用命令
php artisan sitemap:load:urls
当您需要重写特定模型的 URL 时,可以使用选项 --model=App/Models/Pages
php artisan sitemap:load:urls --model=App/Models/Pages
要创建 sitemap,请使用命令
php artisan sitemap:generate
或者您也可以使用界面按钮。
我们可以发布什么?
php artisan vendor:publish --tag=sitemap-config
php artisan vendor:publish --tag=sitemap-lang
php artisan vendor:publish --tag=sitemap-migrations
php artisan vendor:publish --tag=sitemap-styles
php artisan vendor:publish --tag=sitemap-views
说明
其他配置说明在配置文件中。