Laravel optional routing parameter

我的梦境 提交于 2019-12-13 02:18:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!