2014-01-09 60 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