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 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100