简体   繁体   English

在Laravel 5中生成XML Sitemap

[英]Generating an XML Sitemap in Laravel 5

I have a laravel application that is still in the development stages. 我有一个laravel应用程序仍处于开发阶段。 I am currently trying to generate a sitemap for the application using Spatie\\Sitemap\\SitemapGenerator but my code isn't working. 我目前正在尝试使用Spatie \\ Sitemap \\ SitemapGenerator为应用程序生成一个站点地图,但是我的代码无法正常工作。 This is my sitemap code in a file called GenerateSiteMap.php: 这是我的Sitemap代码,位于一个名为GenerateSiteMap.php的文件中:

<?php

use Spatie\Sitemap\SitemapGenerator;

class GenerateSiteMap
{
    public function generateSite()
    {
        $generator = SitemapGenerator::create('http://127.0.0.1:8000/')->writeToFile('sitemap.xml');
        return $generator;
    }
}

It doesn't give me any errors when I run it, it just doesn't do anything. 它在运行时不会给我任何错误,只是什么也没做。 Any idea how I can fix it? 知道我该如何解决吗?

If your file is at public folder you need to add public_path 如果文件位于公用文件夹中,则需要添加public_path

$generator = SitemapGenerator::create('http://127.0.0.1:8000/')->writeToFile(
public_path('sitemap.xml'));

otherwise it might be a permission issue 否则可能是权限问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM