2016-06-23 248 views
0

我在Laravel 5.2這樣的路由:Laravel 5動態控制器路由

Route::group([ 'prefix' => 'users/{hash}/addresses', 'as' => 'admin.addresses.' ], function() { 
    Route::get('getdata', [ 'as' => 'getdata', 'uses' => '[email protected]' ]); 
    Route::get('create', [ 'as' => 'create', 'uses' => '[email protected]' ]); 
    Route::post('create', [ 'as' => 'store', 'uses' => '[email protected]' ]); 
}); 

如何設置我的動作控制器的名字在我的路由組申報?

它的假設是這樣的:

Route::group([ 'prefix' => 'users/{hash}/addresses', 'as' => 'admin.addresses.', 'controller' => 'AddressController' ], function() { 
    Route::get('getdata', [ 'as' => 'getdata', 'uses' => 'getData' ]); 
    Route::get('create', [ 'as' => 'create', 'uses' => 'create' ]); 
    Route::post('create', [ 'as' => 'store', 'uses' => 'store' ]); 
}); 

回答

0

可以使用資源的路線。

Route::resource('users/{hash}/addresses/admin.addresses', 'AddressController'); 

如果您只需要索引並創建,您可以像這樣指定它。

Route::resource('users/{hash}/addresses/admin.addresses', 'AddressController', ['only' => ['index', 'store']]); 
+0

如何設置資源路由的別名? 「as」=>「admin.addresses.blabla」 – yudijohn

+0

我編輯我的答案。你想添加url路徑作爲資源參數 – IshaS

+0

如果你在組「users/{hash}/addresses」中有這條路由,你只需要添加「admin.addresses」作爲資源參數 – IshaS