dp411805872 2017-09-06 10:31
浏览 62
已采纳

Laravel价格过滤中间

I have price filter slider on my Laravel project and I am using Bootstrap slider.

Here is my input code on view

<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()"/>

Here is my auto submit script on Javascript

<script> 
    function checkBoxHandler() { 
        $('#color_form').submit(); 
    } 

    $("#ex2").slider({});
</script>

Here is my 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);

And I got the following error

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 = ?))

  • 写回答

1条回答 默认 最新

  • dtotwai720621 2017-09-06 10:36
    关注

    For whereBetween, you need to pass array.

    whereBetween('price', explode(',', $price))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输