我的 Laravel 项目上有价格过滤器 slider ,我正在使用 Bootstrap slider .
这是我查看的输入代码
<input name="price" id="ex2" type="text" class="span2" value="" data-slider-min="10" data-slider-max="2000" data-slider-step="5" data-slider-value="[250,450]" onchange="checkBoxHandler()"/>
这是我的 Javascript 自动提交脚本
<script>
function checkBoxHandler() {
$('#color_form').submit();
}
$("#ex2").slider({});
</script>
这是我的 Controller
$price = $request->price;
if (request()->has('price')) {
$products = product::whereBetween('price', [$price])
->whereHas('categories', function ($query) use ($tags){
$query->where('name', $tags);
})->paginate(20);
我收到以下错误
SQLSTATE[HY093]: Invalid parameter number (SQL: select count(*) as aggregate from
products
whereprice
between 250,1400 and swim and exists (select * fromcategories
inner joincategory_product
oncategories
.id
=category_product
.category_id
whereproducts
.id
=category_product
.product_id
andname
= ?))
最佳答案
对于whereBetween,您需要传递数组。
whereBetween('price', explode(',', $price))
关于php - Laravel 价格过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46072942/