public function (Request $request)
{
$geturl = $request->path();
$string = 'whatever';
$replace = str_replace($geturl, $string, $geturl);
return response()->json(['Replaced' => $replace]);
}
$query = $_GET;
// replace parameter(s)
$query['d'] = 'new_value';
// rebuild url
$query_result = http_build_query($query);
// new link
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?<?php echo $query_result; ?>">Link</a>