【问题标题】:How to use array for ->whereMonth Laravel?如何将数组用于-> whereMonth Laravel?
【发布时间】:2018-03-22 23:10:08
【问题描述】:

是否可以使用数组作为函数 DB 的值:

->whereMonth($month);

像这样:->whereMonth([01, 02, 12]);

【问题讨论】:

    标签: laravel laravel-5 laravel-5.3


    【解决方案1】:

    whereMonth 不支持数组,第一个参数是列名,不是值。

    https://laravel.com/api/5.3/Illuminate/Database/Query/Builder.html#method_whereMonth

    您可以将 whereIn 与原始表达式一起使用:

    ->whereIn(DB::raw('MONTH(column)'), [1,2,3])
    

    【讨论】:

    • 我决定使用过滤器来收集结果
    猜你喜欢
    • 2021-05-13
    • 2019-04-29
    • 1970-01-01
    • 1970-01-01
    • 2019-05-09
    • 2021-07-29
    • 2021-06-25
    • 2019-06-26
    • 2014-08-12
    相关资源
    最近更新 更多