如何检查一个表字段是null是否从其他表字段中选择数据并订购它
我有两个表1(出勤)和2(出席率_corthe),我正在询问此问题以使用时间字段以ASC顺序出勤:
foreach ($employee_calendars as $key => $employee_calendar) {
$employee_calendar->attendance = Attendance::where("employee_id", $employee->id)
->whereDate("date", "=", $employee_calendar->date)
->orderBy('time', 'asc')
->with("requests")
->get();
}
问题是,当我出勤表中的时间字段无效时,将这些数据放在响应中, NULL的情况我想检查此出席的出勤校正是否有任何出席检查correct_time字段在出席_correction中而不是出勤时间字段,以下是我的表图,我的表图是带有突出显示的行,我也有出勤表(请求)的关系
public function requests()
{
return $this->hasMany("App\Models\AttendanceCorrection", "attendance_id");
}
。 a href =“ https://i.sstatic.net/604ku.png” rel =“ nofollow noreferrer”> atcationance_correction table
I have two tables 1(Attendance) and 2(Attendance_correction) I am querying this to get attendance in asc order using time field:
foreach ($employee_calendars as $key => $employee_calendar) {
$employee_calendar->attendance = Attendance::where("employee_id", $employee->id)
->whereDate("date", "=", $employee_calendar->date)
->orderBy('time', 'asc')
->with("requests")
->get();
}
problem is that when time field in my attendance table is null it puts this data on top of response, in the case of null I want to check if there is any attendance correction of this attendance check correct_time field in attendance_correction instead of attendance time field following are my table pictures with highlighted rows, I also have relation in attendance table (requests) for attendance_correction table:
public function requests()
{
return $this->hasMany("App\Models\AttendanceCorrection", "attendance_id");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以做这样的事情:
You can do something like this: