离开:
id | user_id | start_date |
---|---|---|
1 | 2022-06-01 | 22022-06-03 |
如果你也在模型中定义了关系,你可以在控制器中加载约束:
$users = User::with(['leaves' => function ($query) {
$query->where('start_date', '>=', Carbon::now()))
->where('end_date', '<=', Carbon::now()));
}])->get();
这样,您就不必在刀片模板中进行查询,只需检查count($row->leaves) > 0
你尝试过这个吗:
CarbonCarbon::now()->between($row->leaves()->last()->start_date,$row->leaves()->last()->end_date) ? 'On Leave' : 'Present';