我有这样的路线:Laravel - 重定向路由具有可选参数
Route::get('search/{state?}/{city?}/{brand?}/{model?}', array('as'=>'search-cars'), function($a=false, $b=false, $c=false, $d=false) {
// Do stuff
}
如何从我的控制器将参数传递给上面的路线?我已经试过:
public function postHomeSearch() {
$state= (Input::get('state')) ? Input::get('state') : null;
$city = (Input::get('city')) ? Input::get('city') : null;
$brand= (Input::get('brand')) ? Input::get('brand') : null;
$model= (Input::get('model')) ? Input::get('model') : null;
$data = array(
'state' => $state,
'city' => $city,
'brand' => $make,
'model' => $model,
);
return Redirect::route('search-cars',$data); // <---- HERE
}
请注意,如果他们不选择
你的代码只是似乎不错。如果数组为null,是否尝试过不在数组中包含参数?此外,匹配功能签名上的参数名称。 – facundofarias 2015-02-07 19:23:04
这个解决方案有什么不起作用? – lukasgeiter 2015-02-07 19:25:46
@facundofarias和lukasgeiter ...我在调用postHomeSearch()时得到这个URL ** http:// localhost/laravel/App/public/search /// California ///全部** - 注意三重**/// ** – Daniel 2015-02-07 19:28:38