Php 搜索查询Laravel中缺少IndexController的参数1

Php 搜索查询Laravel中缺少IndexController的参数1,php,laravel-4,Php,Laravel 4,因此,我试图用一个表单中的多个参数进行查询,以执行属性搜索方法。但是我一直在努力使用我的showResults方法,因为我不断地得到IndexController::showResults()缺少的参数1。我还想确定如何搜索属性和类别之间的多对多关系类别[]在我的表单中是一个选择倍数 这是到目前为止我的代码 Route::get('buscar/propiedades', array('as' => 'search', 'uses' => 'IndexController@showR

因此,我试图用一个表单中的多个参数进行查询,以执行属性搜索方法。但是我一直在努力使用我的
showResults
方法,因为我不断地得到IndexController::showResults()缺少的参数1。我还想确定如何搜索属性和类别之间的多对多关系<代码>类别[]在我的表单中是一个选择倍数

这是到目前为止我的代码

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

验证必须失败,这意味着未定义作为参数传递的变量

在设置变量后尝试调用方法,或者设置变量并调用方法

尝试:

在伪代码中,这将:

  • 使用输入和规则数组创建验证器
  • 如果失败,则重定向到根路由,而无需输入
  • 如果通过,它会将所有变量设置为与输入相等,并将这些变量作为参数调用
    showResults
    方法

  • 最后重定向到您的URI。

    所有变量都正确显示。我想问题出在查询中$categories是一个数组,我不知道它是否导致了错误如果它没有选择正确的数据,我们需要查看您的架构/模型,以便了解原因。我已经编辑了代码,但仍然缺少IndexController::showResults()的参数1。是否有与此方法关联的路由,它是否有路由参数?route::get('buscar/propiedades',数组('as'=>'搜索','使用'=>'IndexController@showResults);路由::post('buscar/propiedades',数组('as'=>'搜索','uses'=>'IndexController@searchProperties'));
    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');
    }