我有一個表格來標記員工的出勤情況,HR填寫在每個當前員工的循環中。我需要它顯示數據庫中出席考勤的當前值,否則它應該是空白的。Foreach循環沒有正確地通過
在我控制我查詢了已有的結果:
$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