I have this code :
$employee_calendar->attendance = Attendance::leftJoin("attendance_corrections", function ($join) {
$join->on("attendance_corrections.attendance_id", "=", "attendance.id")
->where("attendance_corrections.status", "!=", "rejected");
})
->select('attendance.*', DB::raw('IF(`time` IS NOT NULL, `time`, attendance_corrections.correct_time) as `correctTime`'))
->where("attendance.employee_id", $employee->id)
->whereDate("attendance.date", "=", $employee_calendar->date)
->orderBy('correctTime', 'asc')
->with("requests")
->distinct()
->get();
I want to check if correctTime is null then dont show this data. I have tried ->whereNotNull('correctTime') it is giving error say column not found.
像这样使用它
->whereNotNull('attendance_corrections.correct_time')
由于它是一个派生列,因此您必须使用 having 子句,原始查询的最佳之处在于您可以使用多种类型的运算符,例如 AND、OR 等,只需将其作为字符串传递即可。
->havingRaw("correctTime IS NOT NULL")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.