如何使用数组 ->whereMonth Laravel?

Kar*_*bah 1 laravel laravel-5 laravel-5.3

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

->whereMonth($month);
Run Code Online (Sandbox Code Playgroud)

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

Dev*_*von 5

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

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

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

->whereIn(DB::raw('MONTH(column)'), [1,2,3])
Run Code Online (Sandbox Code Playgroud)