Saturday, March 11, 2017

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

  });

});



via Zada1100

Advertisement