如何使用数组 - > whereMonth Laravel?

时间:2018-03-22 23:10:08

标签: laravel laravel-5 laravel-5.3

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

->whereMonth($month);

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

1 个答案:

答案 0 :(得分:3)

whereMonth does not support arrays, and the first argument is the column name, not the value.

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

You can instead use whereIn with a raw expression:

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