简体   繁体   中英

Routing with multiple parameters in laravel

I want to have two possibilities with my url:

  1. /en/section/1
  2. /en/section/1/furniture/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. Right now if I put only /en/section/1 in my url I get this error:

Missing required parameters for [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.

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

  });

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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