拉拉维尔搜索并在两个字段之间获取


laravel search and get between two field

我需要在我使用的字段之间获取数字,但我没有得到正确的结果我的输入已提交un_price_from和un_price_to

和我的控制器

        $unit = DB::table('units')->whereIn('un_status', [1]);
        if ($request->has('un_price_from','un_price_to')){
            $unit->whereBetween('un_price', [$request->un_price_from, $request->un_price_to]);
         }
        elseif ($request->has('un_price_from')){
            $unit->where('un_price', $request->un_price_from);
        }
        elseif ($request->has('un_price_to')){
            $unit->where('un_price', $request->un_price_to);
        }

我发现问题出在数据库中,(价格)字段是varchar,我更改为十进制并且工作正常。感谢大家