我正在使用laravel框架,但在此WhereBetween中无法正常工作。我正在使用价格范围,价格从1到500开始。当我设定价格1-100 它给了我1到100之间的所有记录,即20,40,50等。当我从1到150更改值时,上面的结果将不会显示,它不会给我任何结果(20,40,50)。谁能帮我 。这是我的代码
enter code here
$products = Product::with("productimages")
->whereBetween('price',[$data['from'], $data['to']])
->get();
注意: - $ data ['from']起始值,即1和$ data ['to']结束值,即150或更多
答案 0 :(得分:1)
使用Where之间
$projects = Product::where('created_at', '>', $data['from'])
->where('created_at', '<', $data['to'])
->get();
或强>
$current = Product::with("productimages")
->whereBetween('created_at', array($data['from'], $data['to']))->get();
或强>
DB::table('Product')->whereBetween('created_at', array($data['from'], $data['to']))->get();
答案 1 :(得分:0)
我刚刚遇到了同样的问题。当值的数据类型不是整数时,它的行为将非常不可预测。所以解决方案是更改列的数据类型或在获取时强制转换,如下所示:
Data failed to compile:
----------
State 'chrome' in SLS 'software/update-software' is not formed as a list
----------
State 'putty' in SLS 'software/update-software' is not formed as a list
----------
State 'winscp' in SLS 'software/update-software' is not formed as a list
我实际上在 PostgreSQL jsonb 数据类型上遇到了这个问题,因为它总是将嵌套值作为字符串返回,并且在获取之间无法正常工作。