问题
I am trying to build up my routes file and for the application we are building we may have a route such as:
/services/{game}/{id}
Is there a way to have that {game}
parameter, but not actually pass it to the controller? Its basically there, but doesn't have to be anything specific and the controller doesn't need to know its there, it's purely for the users eye to make their URL make sense.
回答1:
That is perfectly possible, you can catch it in the controller without doing anything with it, however you will have to catch it.
回答2:
Do what Bielco said or just minify your route using slugs instead 2 parameters.
For example:
- Game: Skyrim Legendary Edition
- Slug (unique): skyrim-legendary-edition
- Your route: /services/game/skyrim-legendary-edition
In Laravel routes.php
Route::get('services/games/{slug}', 'ServicesController@showGame');
来源:https://stackoverflow.com/questions/22577717/laravel-optional-routing-parameter