2014-02-07 66 views
3

我分組profile控制器,我想鏈接到。然後我定義這條路線:Laravel鏈接路徑沒有定義

//Group to put all the routes that need login first 
Route::group(array('prefix'=> 'admin', 'before' => 'csrf'), function(){ 
    Route::resource('/profile' , 'ProfileController', array('as'=>'profile')); 
}); 

,這是我的菜單鏈接:

<li><a href="{{ URL::route('admin.profile') }}">profile Managment</a></li> 

route在終端這一點,我的結果:

+--------+----------------------------------+------------------------+---------------------------+----------------+---------------+ 
| Domain | URI        | Name     | Action     | Before Filters | After Filters | 
+--------+----------------------------------+------------------------+---------------------------+----------------+---------------+ 
|  | GET/       | index     | Closure     |    |    | 
|  | GET admin/index     | dashboard    | Closure     |    |    | 
|  | GET logout      | logout     | Closure     |    |    | 
|  | POST auth      | auth     | Closure     | csrf   |    | 
|  | GET login      | login     | Closure     |    |    | 
|  | GET admin/profile    | admin..profile.index | [email protected] | csrf   |    | 
|  | GET admin/profile/create   | admin..profile.create | [email protected] | csrf   |    | 
|  | POST admin/profile    | admin..profile.store | [email protected] | csrf   |    | 
|  | GET admin/profile/{profile}  | admin..profile.show | [email protected] | csrf   |    | 
|  | GET admin/profile/{profile}/edit | admin..profile.edit | [email protected] | csrf   |    | 
|  | PUT admin/profile/{profile}  | admin..profile.update | [email protected] | csrf   |    | 
|  | PATCH admin/profile/{profile} |      | [email protected] | csrf   |    | 
|  | DELETE admin/profile/{profile} | admin..profile.destroy | [email protected] | csrf   |    | 
+--------+----------------------------------+------------------------+---------------------------+----------------+---------------+ 

現在我得到這個錯誤:

ErrorException 

Route [admin.profile] not defined. (View: /var/www/alachiq/app/views/back_end/menu.blade.php) (View: /var/www/alachiq/app/views/back_end/menu.blade.php) (View: /var/www/alachiq/app/views/back_end/menu.blade.php) 
+1

在你的路線名admin配置文件註冊爲「admin..profile」用雙點。我認爲是與「/ profile文件」嘗試「曲線」 – luxcem

回答

4

刪除th e /字符從您的Route::resource方法。這是造成雙點,這反過來導致你的錯誤信息。

應該是:

Route::resource('profile' , 'ProfileController', array('as'=>'profile'));

兩種格式(/profileprofile)通常會工作,但使用prefix選項與Route::group當你需要從資源URL刪除/

編輯:另外在我看來,你應該指向你的鏈接路線admin.profile.index,而不是admin.profile

+0

我現在收到此錯誤:'照亮\會議\ TokenMismatchException' –

+1

這就是你CSRF令牌......不匹配......你路線的作品按你的問題。 –

2

爲什麼你不只是做URL::to('admin/profile');

既然你想實現與URL::route('admin.profile');什麼是幾乎相同數量的類型了。

現在從我個人理解,URL::route('profile');會產生一個完整的URL字符串與您分配給同一名稱的路線。

編輯

echo URL::route('admin.profile.index'); 

應該工作。基於Docs,您應該在ROUTE NAME下包含.index。