[英]Laravel redirect to other route
我有一个函数getLocation,该路由名为“ search.location”,例如URL www.url.com/service/ny/slug。 这显示一个位置。
现在,我想检查一下该位置是否可用。 如果具有给定参数的位置不可用,我希望将具有参数service和city的路由称为“ search.servicecity”。 网址为www.url.com/service/ny/。 如何通过参数调用路由?
public function getLocation($servicename, $city, $slug){
$location = Location::where([
['slug','=',$slug],
['city','=',$city]
])->first();
if(count($location)>0){
return view('search.location')->with('servicename',$servicename)
->with('city',$city)->with('information','getLocation')
->with('slug',$slug)->with('location',$location);
}else{
//call search.servicecity with parameters $servicename and $city
}
}
您可以为此使用redirect
帮助器。
return redirect()->route('search.servicecity', [
'service' => $servicename,
'city' => $city,
]);
查看文档以获取其他示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.