是否有办法更改一个或多个"路由的参数",并根据修改后的参数重新构建网址,例如:更改" $ page"值。
我尝试了很多方法:
Route::current()->setParameter('page', ++$page);
// also try
Request::route()->setParameter('page', ++$page);
但总是在重新请求时,URL:
$request->path(); //return path with origin parameter value
$request->url(); //return path with origin parameter value
有没有办法替换"参数"值然后检索更新值的URL? 感谢,
答案 0 :(得分:0)
我这样处理:(在控制器功能中)
Request::route()->setParameter('page', ++$page); //new parameter value
$parameters = Route::current()->Parameters();
$uri = Route::current()->uri();
$uri = substr($uri, 0, strpos($uri, '/{'));
$full_url = Request::fullUrl();
$full_url = substr($full_url, 0, strpos($full_url, $uri));
$full_url = $full_url.$uri.'/'.implode('/',$parameters);
return $full_url;
步骤:
答案 1 :(得分:0)
$url = Request::url(); // url without query
$query = Request::query(); // query
//Replace parameter:
$newFullUrl = $url.'?'. http_build_query(array_merge($query, ['parameter' => 'value']);