简体   繁体   English

在Laravel中使用多个参数进行路由

[英]Routing with multiple parameters in laravel

I want to have two possibilities with my url: 我想在网址中使用两种方法:

  1. /en/section/1 / EN /部分/ 1
  2. /en/section/1/furniture/1 / EN /节/ 1 /家具/ 1

If there's only the content of the first url I want to use SectionController and if there's the content of the second url I want to use FurnitureController. 如果只有第一个URL的内容,我想使用SectionController,如果有第二个URL的内容,我想使用FurnitureController。 Right now if I put only /en/section/1 in my url I get this error: 现在,如果我仅在网址中添加/ en / section / 1,则会出现此错误:

Missing required parameters for [Route: app.furniture.get] [URI: {lang}/section/{id_section}/furniture/{id}] 缺少[Route:app.furniture.get] [URI:{lang} / section / {id_section} / furniture / {id}]的必需参数

I want to know if there's a way to do it. 我想知道是否有办法。 Here is what I have right now: 这是我现在所拥有的:

Route::group(["prefix" => "/{lang}"], function() {

  Route::group(["prefix" => "section"], function() {

    // Get a section
    Route::get("{id}", [
      "uses" => "SectionController@get",
      "as" => "app.section.get"
    ]);

    // Get a furniture
    Route::get("{id_section}/furniture/{id}", [
      "uses" => "FurnitureController@get",
      "as" => "app.furniture.get"
    ]);

  });

});

You can use the id in the group. 您可以在组中使用ID。

Route::group(["prefix" => "/{lang}"], function() {

  Route::group(["prefix" => "section/{id}"], function() {

    // Get a section
    Route::get("", [
      "uses" => "SectionController@get",
      "as" => "app.section.get"
    ]);

    // Get a furniture
    Route::get("furniture/{id}", [
      "uses" => "FurnitureController@get",
      "as" => "app.furniture.get"
    ]);

  });

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM