[英]How to remove parameter from a URL in laravel 5.2
How can I remove the parameters from a URL after processing in my controller?在我的 controller 中处理后,如何从 URL 中删除参数? Like this one:
像这个:
mydomain/mypage?filter%5Bstatus_id%5D
to至
mydomain/mypage
I want to remove the parameters after the ?
我想删除之后的参数
?
then I want to use the new URL in my view file.然后我想在我的视图文件中使用新的 URL 。 Is this possible in laravel 5.2?
这在 laravel 5.2 中是否可行? I have been trying to use other approaches but unfortunately they are not working well as expected.
我一直在尝试使用其他方法,但不幸的是它们没有按预期工作。 I also want to include my data in my view file.
我还想将我的数据包含在我的视图文件中。 The existing functionality is like this:
现有的功能是这样的:
public function processData(IndexRequest $request){
//process data and other checkings
return view('admin.index')
->with([
'data' => $data,
'person' => $persons,
]);
}
I want it to be like:我希望它像:
public function processData(IndexRequest $request){
//process data and other checkings
// when checking the full url is
// mydomain/mypage?filter%5Bstatus_id%5D
// then I want to remove the parameters after the question mark which can be done by doing
// request()->url()
// And now I want to change the currently used url using the request()->url() data
return view('admin.index')
->with([
'data' => $data,
'person' => $persons,
]);
}
I'm stuck here for days already.我已经被困在这里好几天了。 Any inputs are appreciated.
任何输入表示赞赏。
You can use request()->url()
, it will return the URL without the parameters您可以使用
request()->url()
,它将返回不带参数的 URL
public function processData(IndexRequest $request){
$url_with_parameters = $request()->url();
$url= explode("?", $url_with_parameters );
//avoid redirect loop
if (isset($url[1])){
return URL::to($url[0]);
}
else{
return view('admin.index')
->with(['data' => $data,
'person' =>$persons,]);
}
}
add new url to your routes and assuming it will point to SomeController@SomeMethod, the SomeMethod should be something like:将新的 url 添加到您的路由并假设它将指向 SomeController@SomeMethod,SomeMethod 应该类似于:
public function SomeMethod(){
// get $data and $persons
return view('admin.index')
->with(['data' => $data,
'person' =>$persons,]);
}
I hope this helps我希望这有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.