How to make multiple routes share the same URL structure or URL parameters

If you have the following URLs:

/control-panel/{team_id}/
/control-panel/{team_id}/schedule
/control-panel/{team_id}/delete
        etc...

(They all share the first part of the URL – /control-panel/{team_id})

Then you don’t have to write out the routes like this:

Route::get("control-panel/{team_id}","TeamController@index");
Route::get("control-panel/{team_id}/schedule","TeamController@schedule");
Route::delete("control-panel/{team_id}/delete","TeamController@destroy");

Instead, you can group the routes and add a prefix:

Route::group(["prefix"=>"control-panel/{team_id}"], function() {
    Route::get("/","TeamController@index");
    Route::get("schedule","TeamController@schedule");
    Route::delete("delete","TeamController@destroy");
});

Putting a group within a group

You can also put a Route::group() inside another one.

Route::group(["prefix"=>"control-panel/{team_id}"], function() {
    Route::get("/","TeamController@index");
 
    Route::group(["prefix"=>"schedule"],function() {
        Route::get("/","TeamController@schedule");
        Route::post("/add_new","TeamController@store");
    }
    Route::delete("delete","TeamController@destroy");
});
Share on facebook
Facebook
Share on vk
VK
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on reddit
Reddit