首頁  >  文章  >  後端開發  >  laravel5.2定義資源路由之後在blade模板中解析路由出現問題

laravel5.2定義資源路由之後在blade模板中解析路由出現問題

WBOY
WBOY原創
2016-08-10 09:07:151594瀏覽

在使用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') }}則不出錯。請問下問題出在哪裡?

你此時從資料庫讀取的只是對象的字串,而並非是一個對象,需要轉換成對象才可以執行

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn