2014-10-09 48 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