public function (Request $request) { $geturl = $request->path(); $string = 'whatever'; $replace = str_replace($geturl, $string, $geturl); return response()->json(['Replaced' => $replace]); }