我有此代码来获取状态为未完成(I)的会议中的用户注册。
$IncRegistrations = $user->registrations()->where('status', 'I')->count();
但是,您是否知道如何在状态不完整的会议中获取用户注册,而仅针对“ end_date”列小于now()的会议(即尚未完成的会议)进行注册?
您可以使用 whereDate
$IncRegistrations = $user->registrations()
->where('status', 'I')->whereDate('end_date', '<', Carbon::now())->count();
使用注释后编辑whereHas
$IncRegistrations = $user->registrations()
->where('status', 'I')
->whereHas('conference', function($query){
$query->whereDate('end_date', '<', Carbon::now());
})->count();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句