duanbai1974 2017-09-05 17:48
浏览 245
已采纳

在Laravel中更改动态get route参数

I am having trouble to understand how to change a get Route with a dynamic parameter in Laravel. I have a route that dynamically adds company names as route parameters, something along the lines of www.page.com/{name_of_company}

In my web.php, the route looks like this:

Route::get('/{company_name}', ['uses' => 'Frontend\CompanyController@show', 'as' => 'CompanyShow']);

I now need to change the {company_name} variable though, for example to remove whitespace, change certain characters etc. so I was planning to use some sort of str_replace function, I just need to know where I have to apply this function to the dynamic parameter so that it gets successfully called with the newly "cleaned" name version in the URL. I tried to directly manipulate the dynamic variable inside of the get route and I also tried to use middleware, but I didn't know how to do it in the end, so I am asking the question here and hope someone has an idea on how to accomplish this ...

  • 写回答

1条回答 默认 最新

  • doutuobao9736 2017-09-05 17:53
    关注

    Try something like this in your middleware, you can override request parameters that way

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 (标签-STM32|关键词-智能小车)
  • ¥20 关于#stm32#的问题,请各位专家解答!
  • ¥15 (标签-python)
  • ¥20 搭建awx,试了很多版本都有错
  • ¥15 java corba的客户端该如何指定使用本地某个固定IP去连接服务端?
  • ¥15 activiti工作流问题,求解答
  • ¥15 有人写过RPA后台管理系统么?
  • ¥15 Bioage计算生物学年龄
  • ¥20 如何将FPGA Alveo U50恢复原来出厂设置哇?
  • ¥50 cocos2d-x lua 在mac上接入lua protobuf?