“如何调试”;array_key_exists()要求参数2为数组,给定整数;在PHP中?

“如何调试”;array_key_exists()要求参数2为数组,给定整数;在PHP中?,php,jquery,mysql,laravel,Php,Jquery,Mysql,Laravel,我在学习拉威尔,还有很多东西要学。最近一直在练习,现在我想在同一页中根据类别的选择对表“robots”进行查询,然后如果我愿意,根据该选择进行新的查询并添加价格范围选择。但它得到了一个错误:“array\u key\u exists()期望参数2是数组,给定整数”。我甚至不知道错误在哪里 Laravel版本是5.4。本例中的表是:机器人、类别 代码如下: 控制器 function catalog(Request $request) { $categories = DB::table('c

我在学习拉威尔,还有很多东西要学。最近一直在练习,现在我想在同一页中根据类别的选择对表“robots”进行查询,然后如果我愿意,根据该选择进行新的查询并添加价格范围选择。但它得到了一个错误:“array\u key\u exists()期望参数2是数组,给定整数”。我甚至不知道错误在哪里

Laravel版本是5.4。本例中的表是:机器人、类别

代码如下:

控制器

function catalog(Request $request) {
    $categories = DB::table('categories')->pluck('Category', 'id');
    $categoryesc = $request->categoryesc;
    $robots = DB::table('robots')->where('Category_id', $categoryesc)->get();
    $priceesc = $request->priceesc;
    $robots2 = DB::table('robots')->where('Category_id', $categoryesc AND 'Price', '<=', $priceesc)->get();
    return view('catalog', compact('robots', 'categories'));
}

此查询是导致错误的原因:

$robots2 = DB::table('robots')->where('Category_id', $categoryesc AND 'Price', '<=', $priceesc)->get();

除非您使用
或where()
或像
where('Price',我看不到您的代码中存在任何数组键(),否则它们将在后台自动与
链接在一起。请修改我编辑代码的代码段。现在出现错误:“非法运算符和值组合”看起来您有两个表单,这意味着当您提交一个表单时,您不会从另一个表单提取输入,这取决于哪个
$request->categoryesc;
$priceesc=$request->priceesc;
为空,并且您不能使用
where('Price','
        $('#categoryesc').on('change', function chcat(){
        $(this).closest('form').submit();
        });

        $('#priceesc').on('change', function chpri(){
        $(this).closest('form').submit();
        });
$robots2 = DB::table('robots')->where('Category_id', $categoryesc AND 'Price', '<=', $priceesc)->get();
$robots2 = DB::table('robots')->where('Category_id', $categoryesc)->where('Price', '<=', $priceesc)->get();