Search code examples
phplaravelbackendsitemaplaravel-sitemap

I'm using spatie/laravel-sitemap is it possible to set another APP_URL for these url


here I'm using sitemap

    $sitemap = Sitemap::create()->add(Url::create('/content'));
    
    $sitemap->writeToFile(public_path($this->path));

and this is sitemap.xml

<url>
    <loc>http://api-core.test/content</loc>
    <lastmod>2020-09-09T11:30:51+04:30</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.8</priority>
</url>

is there any way to change api-core.test without changing env


Solution

  • I found a way to change baseurl if string in Url::create('http://example.com/content') contain http create function does not paste the url at the beginning of the string

    sitemap will change to

    <url>
         <loc>http://example.com/content</loc>
         <lastmod>2020-09-09T11:30:51+04:30</lastmod>
         <changefreq>daily</changefreq>
         <priority>0.8</priority>
    </url>
    

    even if APP_URL is somthing else