【问题标题】:laravel whereraw with where in statementlaravel whereraw 与 where 语句
【发布时间】:2014-01-09 10:13:43
【问题描述】:

我正在尝试使用 whereRaw 在查询生成器中使用 WHERE IN 语句,但它似乎不起作用。我不是试图从其他表中选择值,只是从多个值中选择。

我尝试了这 3 种方法:

return $this->object->whereRaw("`status` = 'active' AND `salesType` IN ( ? ) AND `region_id` = ?", array("'sale','buy'","1"))->paginate(10);

return $this->object->whereRaw("`status` = 'active' AND `salesType` IN ( ? ) AND `region_id` = ?", array("sale,buy","1"))->paginate(10);

return $this->object->whereRaw("`status` = 'active' AND `salesType` IN ( ? ) AND `region_id` = ?", array(array("sale,buy"),"1"))->paginate(10);

【问题讨论】:

    标签: laravel where where-in


    【解决方案1】:

    为什么不使用where 和 whereIn` 方法?

    return $this->object->where('status', '=', $active)->whereIn('salesType', $array);
    

    【讨论】:

    • 事实证明这是最好的方法:)
    猜你喜欢
    • 2017-06-10
    • 2016-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多