首页 文章

在Laravel 5中使用其他URL参数嵌套资源控制器

提问于
浏览
0

我正在尝试为Laravel 5中的嵌套资源控制器创建路由,如..

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

在我正在开发的应用程序中,我有登录应用程序的客户,还有sys-admins . 每个客户都可以选择使用多个模块,在这些模块中,有时会有相同的模型,但他们使用的是不同的控制器 .

我使用了以下解决方案,但它们存在一些问题 .

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() 功能的选项,还是我可以在路径资源中创建一个组?或者我应该用 $options = ['uses' => '...', 'as' => 'customers.module1.clients.*'] 写出所有不同的 Route::getRoute::post 函数

1 回答

  • 3

    您可以声明以下两个路由:

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

    然后你的路线就是这样:
    enter image description here

相关问题