Heim  >  Artikel  >  Backend-Entwicklung  >  laravel5.2定义资源路由之后在blade模板中解析路由出现问题

laravel5.2定义资源路由之后在blade模板中解析路由出现问题

WBOY
WBOYOriginal
2016-08-10 09:07:151594Durchsuche

在使用laravel5.2的过程中,出现了一个小问题,请教一下各位。

我定义了一个资源路由,并把资源路由的名称都存入到数据库中,现在通过数据库查找删选之后得到如下结果:

<code class="php">
    array (size=6)
      0 => 
        object(stdClass)[221]
          public 'id' => int 10
          public 'route' => string 'menu.create' (length=11)
      1 => 
        object(stdClass)[222]
          public 'id' => int 11
          public 'route' => string 'menu.index ' (length=11)    

  </code>

接下来在模板中,我把上面数组中所有的路由名称对应的url全部输出来

<code class="php">
    @foreach($menulist as $menu)
        {{ route($menu->route) }}
    @endforeach
</code>

但是出现错误:

ErrorException in UrlGenerator.php line 314:
Route [menu.index ] not defined.

如果单纯的使用{{ route('menu.index') }}则不出错。请问下问题出在哪里?

回复内容:

在使用laravel5.2的过程中,出现了一个小问题,请教一下各位。

我定义了一个资源路由,并把资源路由的名称都存入到数据库中,现在通过数据库查找删选之后得到如下结果:

<code class="php">
    array (size=6)
      0 => 
        object(stdClass)[221]
          public 'id' => int 10
          public 'route' => string 'menu.create' (length=11)
      1 => 
        object(stdClass)[222]
          public 'id' => int 11
          public 'route' => string 'menu.index ' (length=11)    

  </code>

接下来在模板中,我把上面数组中所有的路由名称对应的url全部输出来

<code class="php">
    @foreach($menulist as $menu)
        {{ route($menu->route) }}
    @endforeach
</code>

但是出现错误:

ErrorException in UrlGenerator.php line 314:
Route [menu.index ] not defined.

如果单纯的使用{{ route('menu.index') }}则不出错。请问下问题出在哪里?

你此时从数据库中读取的只是对象的字符串,而并非是一个对象,需要转化为对象才可以执行

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn