使用eloquent,我试图让所有用户在2月28
或29
(如果是闰年)注册时注册:
// If leap year, get feb 28 and 29 users
$users = \App\User::->whereMonth('created_at', '=', '02')
->whereDay('created_at', '=', '28')
->whereDay('created_at', '=', '29')
->get();
当我们在此处添加额外的29
支票时,上述功能无效:
->whereDay('created_at', '=', '29') // does not work because of whereDay '28' above
理想情况下,这样的东西会起作用,但它在api中不存在:
->whereDayIn('created_at', ['28','29'])
知道如何在2月28
/ 29
这两天内吸引用户?
答案 0 :(得分:2)
试试这个:
$users = \App\User::whereMonth('created_at', '=', '02')
->whereIn(DB::raw('DAY(created_at)'), [28,29])
->get();
答案 1 :(得分:1)
将您的查询更改为:
// If leap year, get feb 28 and 29 users
$days = [28, 29];
$users = \App\User::whereMonth('created_at', '02')
->where(function($query) use($days) {
foreach ($days as $day) {
$query->whereDay('created_at', '=', $day, 'or');
}
})
->get();
OR
// If leap year, get feb 28 and 29 users
$days = [28, 29];
$users = \App\User::whereMonth('created_at', '02')
->whereIn(DB::raw('DAYOFMONTH("created_at")'), $days)
->get();