php - Laravel 价格过滤器

标签 php jquery twitter-bootstrap laravel laravel-5.4

我的 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 where price between 250,1400 and swim and exists (select * from categories inner join category_product on categories.id = category_product.category_id where products.id = category_product.product_id and name = ?))

最佳答案

对于whereBetween,您需要传递数组。

whereBetween('price', explode(',', $price))

关于php - Laravel 价格过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46072942/

相关文章:

javascript - 清空并将html写入Div

javascript - 避免在第一次 ajax 调用完成之前通过 ajax 请求提交多个表单

jquery - Bootstrap 3 : Fix the row height

html - 展开时 div 的高度相同

php - 替换字符串中子字符串每次出现但最后一次出现的有效/简单方法(str_replace_except_last)?

php - PRG模式问题?

php - 如何将数据从一个 View 页面传递到 codeigniter 中的另一个 View ?

javascript - Ember 中的下拉列表;

html - 如何制作内联响应式 Bootstrap 表?

php - 是否可以在 Lumen(by Laravel) 中使用西里尔符号?