2014-10-09 2 views
0

Так что я пытаюсь сделать запрос с несколькими параметрами, выходящими из формы, для выполнения метода поиска свойств. Но я борюсь с моим методом showResults, так как я постоянно получаю Missing argument 1 for IndexController::showResults(). Кроме того, я хочу, чтобы узнать, как выполнять поиск по многим отношениям между категориями и категориями. categories[] - это несколько вариантов в моей форме.Отсутствует аргумент 1 для IndexController в поисковом запросе 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

Ваша валидация должна быть неудачной, означая, что переменные, которые вы передаете в качестве параметров, не определены.

Попробуйте вызвать свой метод после того, как вы установили свои вары, или установите свои вары и вызовите свой метод.

Try:

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

Проверка правильная .. Нет проблем с этим –

+0

Какова ошибка или логическая проблема? –

+0

Все переменные выводятся правильно. Проблема в запросе, я думаю. $ categories - массив, и я не знаю, вызвало ли его ошибку –