2015-10-06 117 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