2014-10-09 50 views
0

所以即时通讯尝试使用多个参数进行查询,从表单中产生一个属性搜索方法。但我一直在努力与我的showResults方法,因为我不断得到Missing argument 1 for IndexController::showResults()。另外,我想确保如何通过属性和类别之间的多对多关系进行搜索。 categories[]是我的表单中的选择倍数。索引控制器在搜索查询中缺少参数1 Laravel

这是我的代码到目前为止。

Route::get('buscar/propiedades', array('as' => 'search', 'uses' => '[email protected]')); 
Route::post('buscar/propiedades', array('as' => 'search', 'uses' => '[email protected]')); 

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

您的验证必须失败,意味着您作为params传递的变量未定义。

尝试打电话给你的方法后,你设置你的瓦尔,或设置你的瓦尔和打电话给你的方法。

尝试:

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'); 
} 

伪代码,这将:

  1. 创建与输入验证程序和您的规则阵列
  2. 如果失败,重定向到根路径,没有输入
  3. 如果通过,它会将所有变量设置为与输入相同,并将这些变量作为参数调用showResults方法。

最后重定向到您的URI。

+0

验证是正确的..没有问题 – 2014-10-09 17:43:03

+0

什么是错误或逻辑问题呢? – 2014-10-09 17:50:19

+0

所有变量都正确输出。问题出在我猜的查询中。 $ categories是一个数组,我不知道它是否导致错误 – 2014-10-09 17:53:18