因此我尝试使用来自表单的多个参数进行查询以执行属性搜索方法。但我正在努力使用showResults
方法,因为我不断获得Missing argument 1 for IndexController::showResults()
。此外,我想确保如何搜索属性和类别之间的多对多关系。 categories[]
是我表单中的选择倍数。
到目前为止,这是我的代码。
Route::get('buscar/propiedades', array('as' => 'search', 'uses' => 'IndexController@showResults'));
Route::post('buscar/propiedades', array('as' => 'search', 'uses' => 'IndexController@searchProperties'));
public function showResults($categories, $activity, $currency, $beds, $baths, $price)
{
return View::make('front.results')
->with('properties', Property::join('category_property', 'properties.id', '=', 'category_property.property_id')
->join('categories', 'category_property.category_id', '=', 'categories.id')
->join('activities', 'activities.id', '=', 'properties.activity_id')
->join('currencies', 'currencies.id', '=', 'properties.currency_id')
->whereIn('categories.id', $categories)
->orWhere('activities.id', '=', $activity)
->orWhere('currencies.id', '=', $currency)
->orWhere('properties.beds', '=', $beds)
->orWhere('properties.baths', '=', $baths)
->orWhere('properties.price', '=', $price)
->paginate(6);
}
public function searchProperties()
{
$validator = Validator::make(Input::all(), Property::$search_rules);
// if the validator fails, redirect back to the form
if ($validator->fails()) {
return Redirect::to('/')
->withInput(); // send back the input (not the password) so that we can repopulate the form
}else{
$categories = Input::get('category_id');
$activity = Input::get('activity_id');
$currency = Input::get('currency_id');
$beds = Input::get('beds');
$baths = Input::get('baths');
$price = Input::get('price');
}
$this->showResults($categories, $activity, $currency, $beds, $baths, $price);
return Redirect::to('buscar/propiedades');
}
答案 0 :(得分:0)
您的验证必须失败,这意味着您作为参数传递的变量未定义。
设置vars后设置调用方法,或设置vars并调用方法。
尝试:
public function searchProperties()
{
$validator = Validator::make(Input::all(), Property::$search_rules);
// if the validator fails, redirect back to the form
if ($validator->fails()) {
return Redirect::to('/')
->withInput(); // send back the input (not the password) so that we can repopulate the form
}else{
$categories = Input::get('category_id');
$activity = Input::get('activity_id');
$currency = Input::get('currency_id');
$beds = Input::get('beds');
$baths = Input::get('baths');
$price = Input::get('price');
$this->showResults($categories, $activity, $currency, $beds, $baths, $price);
}
return Redirect::to('buscar/propiedades');
}
在伪代码中,这将:
showResults
方法。最后重定向到您的URI。