Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
laravel站点地图和转换为xml_Laravel_Seo_Sitemap - Fatal编程技术网

laravel站点地图和转换为xml

laravel站点地图和转换为xml,laravel,seo,sitemap,Laravel,Seo,Sitemap,我在的帮助下写了一个网站地图 这是我的索引: public function siteMap( ) { $news=News::orderBy('time','desc')->where('time','<',time())->where('showview',1)->first(); $categories = Cat::orderBy('id' , 'desc')->first(); $games = Game::orderBy('id

我在的帮助下写了一个网站地图

这是我的索引:

public function siteMap(  )
{
    $news=News::orderBy('time','desc')->where('time','<',time())->where('showview',1)->first();
    $categories = Cat::orderBy('id' , 'desc')->first();
    $games = Game::orderBy('id' , 'desc')->first();
    $genres = Genre::orderBy('id' , 'desc')->first();
    $movies = Movie::orderBy('id' , 'desc')->first();
    $platforms = Platform::orderBy('id' , 'desc')->first();

    return response()->view('siteMap.siteMap', [

        'news'          =>  $news,
        'categories'    =>  $categories,
        'games'         =>  $games,
        'genres'        =>  $genres,
        'movies'        =>  $movies,
        'platforms'     =>  $platforms

    ])->header('Content-Type', 'text/xml');
    }
公共功能站点地图()
{
$news=news::orderBy('time','desc')->其中('time','';?>

{{--posts站点地图--}
//url/{{$news->id}/{{$news->title}
{{date('c',$news->time)}
{{--类别的站点地图--}
//url/{{$categories->id}/{{$categories->name}
{{date('c',$categories->time)}
{{--游戏配置文件的站点地图--}
//url/profiles/games/{{$games->id}}/{{{$games->name}
{{date('c',(整数)$games->time)}
{{--流派配置文件的站点地图--}
//url/{{$genres->id}}/{{$genres->name}
{{date('c',$genres->time)}
{{--movie profile的站点地图--}
//url/{{$movies->id}/{{$movies->name}
{{date('c',(整数)$movies->time)}
{{--平台配置文件的站点地图--}
//url/{{$platforms->id}/{{$platforms->name}
{{date('c',(整数)$platforms->time)}

在主机上上传并使用google webmaster后,我发现以下错误:

您的网站地图显示为HTML页面。请改用受支持的网站地图格式


感谢您的帮助!

确保路由具有xml作为扩展名
route::get('sitemap.xml'…
。不要忘记sitemapindex
侧注,您可以使用
{!!!!}
而不是
@aynber在检查完浏览器后,我发布了这个问题,并且非常确定问题不在于路线。Thanks@Amir_Jani你解决了吗?在使用sitemapindex拆分我的站点地图时,我从google搜索控制台收到了相同的错误。我还没有添加响应
text/xml
,因为旧的站点地图操作没有执行算了。@KeitelDOG我不记得我是怎么修好这个的,但我从laracast的ericlbarnes那里得到了答案
<?php

echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
{{-- site map for posts --}}
<sitemap>
    <loc> //url /{{ $news->id }}/{{ $news->title }}</loc>
    <lastmod>{{ date('c',$news->time) }}</lastmod>
</sitemap>

{{-- sitemap for categories --}}
<sitemap>
    <loc>//url/{{ $categories->id }}/{{ $categories->name }}</loc>
    <lastmod>{{ date('c',  $categories->time) }}</lastmod>
</sitemap>

{{-- sitemap for games profile --}}
<sitemap>
    <loc>//url/profiles/games/{{ $games->id }}/{{ $games->name }}</loc>
    <lastmod>{{ date('c', (integer) $games->time) }}</lastmod>
</sitemap>

{{-- sitemap for genres profile --}}
<sitemap>
    <loc>//url/{{ $genres->id }}/{{ $genres->name }}</loc>
    <lastmod>{{ date('c',  $genres->time) }}</lastmod>
</sitemap>

{{-- sitemap for movie profile --}}
<sitemap>
    <loc>//url/{{ $movies->id }}/{{ $movies->name }}</loc>
    <lastmod>{{ date('c',  (integer) $movies->time) }}</lastmod>
</sitemap>

{{-- sitemap for platforms profile --}}
<sitemap>
    <loc>//url/{{ $platforms->id }}/{{ $platforms->name }}</loc>
    <lastmod>{{ date('c', (integer) $platforms->time) }}</lastmod>
</sitemap>