我有一个表格来标记员工的出勤情况,HR 填写该表格会覆盖每个当前员工。我需要它来显示数据库中标记出勤的当前值,否则它应该是空白的。
在我的控制器中,我查询现有结果:
$results = Attendance::where('Sdate', '=', date("Y-m-d", strtotime($TheDate))) ->get();
然后遍历它们以获取员工详细信息:
foreach($results as $result)
{
$contractors = DB::table('contractors') ->where('contractors.AreaPosition', '=', $department) ->where('PRN', '!=', $result->PRN) ->get(); $employees = DB::table('current_employees') ->where('current_employees.AreaPosition', '=', $department) ->where('PRN', '!=', $result->PRN) ->get(); $showEmployees = array_merge($contractors, $employees);
}
这应该排除在该日期保存了出勤记录的所有员工,但它似乎没有正确循环。它将排除一些结果,但不是全部。如果我返回结果变量,我会得到正确的记录列表,因此我知道该部分工作正常。
在我看来,我希望实现的目标是:
@foreach($attendance as $results)
Show form where there's an existing record for this date and department
@endforeach
@foreach($employees as $employee)
Show form for all employees in this department (but should exclude results where there is a record in attendance)
@endforeach