2015-10-06 114 views
0

我想在Laravel 5創建嵌套資源控制器航線如..嵌套資源控制器5

/customers/{customer}/modulename/clients/{client} 

在應用我開發我有誰在登錄客戶到應用程序,但也是系統管理員。每個客戶都可以選擇多個模塊來使用,而在這些模塊中,有時候會有相同的模型,但他們使用的是不同的控制器。

我已經使用了以下解決方案,但它們存在一些問題。

Route::resource('customers', 'CustomerController'); 
Route::resource('customers.clients', 'CustomerController'); 

我不能去在這個解決方案不同的模塊,所以我試圖讓組...

Route::group(['prefix' => 'customers/{customer}', ''], function(){ 
    Route::group(['prefix' => 'module1', ''], function(){ 
    Route::resource('clients', 'Module1\ClientAController'); 
    }); 
    Route::group(['prefix' => 'module2', ''], function(){ 
    Route::resource('clients', 'Module2\ClientBController'); 
    }); 
}); 
Route::resource('customers', 'CustomerController'); 

但路線越來越討厭。在構建菜單層次結構時,以下路線很難創建。

route('customers.{customer}.module1.clients.index'); 

是它應該是什麼,但我想獲得去...

route('customers.module1.clients.index'); 

有沒有爲Route::group()功能我缺少一個選項,或者我可以做一組在路由資源內?或者我應該只是寫出所有不同Route::getRoute::post功能與該$options = ['uses' => '...', 'as' => 'customers.module1.clients.*']

+1

爲什麼你不使用'Route :: resource('customer.module.client');'? – Mithredate

+0

我想到了這個解決方案,但我想爲不同的客戶端使用不同的控制器 –

回答

3

可以聲明以下兩種途徑:

Route::resource('customer','CustomerController'); 
Route::resource('customer.module.client','ClientController'); 

然後你的路由會像這樣: enter image description here