Spatie Laravel 站点地图生成的 xml 文件为空

Wai*_*ein 9 sitemap laravel

我正在开发 Laravel 应用程序。现在,我正在尝试使用此包https://github.com/spatie/laravel-sitemap为我的网站实现站点地图。但是当我生成 sitemap.xml 时,文件中不包含任何路径。

我安装了运行 Composer 命令的包

composer require spatie/laravel-sitemap
Run Code Online (Sandbox Code Playgroud)

然后我出版了作曲家。

php artisan vendor:publish --provider="Spatie\Sitemap\SitemapServiceProvider" --tag=config
Run Code Online (Sandbox Code Playgroud)

在 routes/web.php 中,我添加了这个。

Route::get('sitemap', function () {
    SitemapGenerator::create('http://app.localhost/')->writeToFile('sitemap.xml');
    return "Sitemap generated".
});
Run Code Online (Sandbox Code Playgroud)

当我运行代码并生成 sitemap.xml 时。当我打开 sitemap.xml 时,这就是我在其中找到的全部内容。

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
</urlset>
Run Code Online (Sandbox Code Playgroud)

我在 web.php 中有很多路由。出了什么问题,如何解决?

Ehi*_*Ehi 3

您可以手动添加其他网址,如下所示,当您运行它时,链接将添加到您的站点地图文件中:

use Spatie\Sitemap\SitemapGenerator;
use Spatie\Sitemap\Tags\Url;

 Route::get('sitemap', function () {
    SitemapGenerator::create('https://vesicash.com/')->getSitemap()
    ->add(Url::create('/link1')->setPriority(0.5))
    ->add(Url::create('/link2')->setPriority(0.5))
    ->add(Url::create('/link3')->setPriority(0.5))
    ->add(Url::create('/privacy')->setPriority(0.5))
    ->writeToFile('sitemap.xml');
    return "Sitemap Generated";
});
Run Code Online (Sandbox Code Playgroud)