pop-sy / laravel-site-map
Laravel的pop-sy/site-map包装器
dev-master
2022-09-13 16:36 UTC
Requires
- php: ^8.0
- illuminate/support: ^8|^9
- popsy/site-map: dev-master
This package is auto-updated.
Last update: 2024-09-13 20:55:09 UTC
README
Laravel包装器,用于Sitemap包
安装
在您的composer.json中要求此包并更新composer。
composer require popsy/laravel-site-map
向config/app.php添加提供者
Popsy\LaravelSiteMap\SitemapServiceProvider::class,
您可以在config/app.php中为Sitemap外观添加别名
'Sitemap' => Popsy\LaravelSiteMap\Facade\Sitemap::class,
您可以发布配置文件
php artisan vendor:publish --provider="Popsy\LaravelSiteMap\SitemapServiceProvider"
使用方法
使用此数据格式
$data = [ [ 'loc' =>"https://site.ru/", 'lastmod' =>"2020-12-14", 'priority' =>1, 'changefreq' =>"hourly" ], [ 'loc' =>"https://site.ru/news", 'lastmod' =>"2020-12-10", 'priority' =>0.5, 'changefreq' =>"daily" ], // ..... ];
例如
use Popsy\LaravelSiteMap\Facade\Sitemap; Sitemap::setType('json') ->setData($data) ->setFilePath(public_path('sitemap.json')) ->generate();
或
public function handle(IGenerator $generator) { $data = [/*....*/]; $generator ->setData($data) ->setFilePath(public_path('sitemap.xml')) ->generate(); }