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主通道和互补通道独立输出
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题