2014-01-09 57 views
2

在Laravel 4.0我的路線文件看起來像這樣:laravel 4.1路由的變化?

Route::group(['prefix' => 'v1'], function(){ 

    // define the user resource with no system 
    Route::resource('users', 'UserController'); 

    Route::get('me', function() { 
     $r = URL::action('[email protected]', [Auth::user()->getAuthIdentifier()]); 
     return Redirect::to($r); 
    }); 

    Route::group(['prefix' => 'systems/{systems}'], function(){ 
     // define the user resource with a system system 
     Route::resource('users', 'UserController'); 
    }); 

}); 

這完美地工作, 因爲我只在一個參數傳遞給URL::action方法參數數組中的/我的路線,將使用系統少路線::資源(「用戶...`如果我是兩個人通過,將利用系統前綴版本。

但在Laravel 4.1,而不是它返回的路線

/v1/systems/[the user id]/users/{users}(文字佔位符{users})。

是什麼導致了這種變化/我該如何解決它?正在註冊

路線的兩組爲php artisan routes輸出有:

GET v1/users       | v1.users.index      | [email protected] 
GET v1/users/create     | v1.users.create     | [email protected] 
POST v1/users       | v1.users.store      | [email protected] 
GET v1/users/{users}     | v1.users.show      | [email protected] 
GET v1/users/{users}/edit    | v1.users.edit      | [email protected] 
PUT v1/users/{users}     | v1.users.update     | [email protected] 
PATCH v1/users/{users}     |         | [email protected] 
GET v1/systems/{systems}/users   | v1.systems.{systems}.users.index | [email protected] 
POST v1/systems/{systems}/users   | v1.systems.{systems}.users.store | [email protected] 
GET v1/systems/{systems}/users/{users} | v1.systems.{systems}.users.show | [email protected] 
PUT v1/systems/{systems}/users/{users} | v1.systems.{systems}.users.update | [email protected] 
PATCH v1/systems/{systems}/users/{users} |         | [email protected] 
DELETE v1/systems/{systems}/users/{users} | v1.systems.{systems}.users.destroy | [email protected] 
+0

AREN你應該使用':systems'而不是'{systems}' –

回答

0

你有兩條路線指向同一個動作:

v1.users.index

v1.systems.{systems}.users.index

(看一看php artisan routes命令輸出中)

URL::action當功能被調用時,Laravel嘗試查找路由的名稱通過在actionMap陣列查找,然後產生使用該名稱的鏈接。

actionMap陣列圖actionname所有路線。

因此,後面的路由定義用於actionMap陣列。

使用URL::routeroute輔助函數生成鏈接到一個名爲路線也經過路線指標的影響有一個關鍵,像這樣:

['systems' => 'someSystem', 'users' => Auth::user()->getAuthIdentifier() ]


Laravel Named Routes

Laravel URLs