核心代码:

$html=view("home.index.sitemap",compact("show"));
return response($html,200)->header("Content-type","text/xml");


模板文件

<?xml version="1.0" encoding="UTF-8"?>
<urlset>
    <url>
        <loc>{{route("index.index.index")}}</loc>
        <lastmod>{{date("Y-m-d")}}
        </lastmod>
        <changefreq>daily</changefreq>
        <priority>1.0</priority>
    </url>
    @foreach($show['column'] as $key)
    <url>
        <loc>{{route('index.index.column',['id'=>$key->id])}}</loc>
        <changefreq>daily</changefreq>
        <priority>0.8</priority>
    </url>
    @endforeach
    @foreach($show['lable'] as $key)
        <url>
            <loc>{{route('index.index.lable',['id'=>$key->id])}}</loc>
            <changefreq>daily</changefreq>
            <priority>0.8</priority>
        </url>
    @endforeach
    @foreach($show['article'] as $key)
    <url>
        <loc>{{route('index.index.lable',['id'=>$key->id])}}</loc>
        <lastmod>{{$key->created_at}}</lastmod>
        <changefreq>0.7</changefreq>
    </url>
    @endforeach
</urlset>