簡體   English   中英

在Laravel中使用多個參數進行路由

[英]Routing with multiple parameters in laravel

我想在網址中使用兩種方法:

  1. / EN /部分/ 1
  2. / EN /節/ 1 /家具/ 1

如果只有第一個URL的內容,我想使用SectionController,如果有第二個URL的內容,我想使用FurnitureController。 現在,如果我僅在網址中添加/ en / section / 1,則會出現此錯誤:

缺少[Route:app.furniture.get] [URI:{lang} / section / {id_section} / furniture / {id}]的必需參數

我想知道是否有辦法。 這是我現在所擁有的:

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"
    ]);

  });

});

您可以在組中使用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