gpt4 book ai didi

php - Laravel 在 url 字符串中更改获取参数并返回

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:57:29 24 4
gpt4 key购买 nike

我正在为搜索过滤器使用 get 参数,并且需要能够更改查询字符串变量的值并返回修改后的 url(作为字符串变量,没有什么特别的,没有重定向或任何东西)。这是我目前所拥有的以及正在发生的事情:

public function index(Request $request){

echo $request->fullUrl();
// outputs https://test.com/search?type=somestring

$request->merge(['type' => 'anotherstring']);

echo $request->fullUrl();
// still outputs https://test.com/search?type=somestring

// is there a way to change a parameter value in the url and
// return the modified url string?

}

我想如果情况变得更糟,我会手动解析字符串,但感觉好像有一种“laravel 方式”可以解决这个问题,而我碰巧错过了?

最佳答案

改用fullUrlWithQuery

echo $request->fullUrlWithQuery(['type' => 'anotherstring']);

关于php - Laravel 在 url 字符串中更改获取参数并返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44375516/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com