[英]How to check if predefined selected column is null is laravel
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.我想检查 correctTime 是否为空,然后不显示此数据。 I have tried ->whereNotNull('correctTime') it is giving error say column not found.
我试过 ->whereNotNull('correctTime') 它给出了错误说找不到列。
像这样使用它
->whereNotNull('attendance_corrections.correct_time')
由于它是一个派生列,因此您必须使用 having 子句,原始查询的最佳之处在于您可以使用多种类型的运算符,例如 AND、OR 等,只需将其作为字符串传递即可。
->havingRaw("correctTime IS NOT NULL")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.