Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 检查日期是否在每个用户的日期范围内_Php_Mysql_Laravel - Fatal编程技术网

Php 检查日期是否在每个用户的日期范围内

Php 检查日期是否在每个用户的日期范围内,php,mysql,laravel,Php,Mysql,Laravel,我正在尝试将用户的缺勤日期指定给他们的日历日期 我在拉威尔收集所有数据 用户的日历如下所示,只是日期: “cal_条目”:[ { “校准日期”:“2021-01-01 00:00:00.000”, }, { “校准日期”:“2021-01-02 00:00:00.000”, }, { “校准日期”:“2021-01-03 00:00:00.000”, }, { “校准日期”:“2021-01-04 00:00:00.000”, }, { “校准日期”:“2021-01-05 00:00:00.0

我正在尝试将用户的缺勤日期指定给他们的日历日期

我在拉威尔收集所有数据

用户的日历如下所示,只是日期:

“cal_条目”:[ { “校准日期”:“2021-01-01 00:00:00.000”, }, { “校准日期”:“2021-01-02 00:00:00.000”, }, { “校准日期”:“2021-01-03 00:00:00.000”, }, { “校准日期”:“2021-01-04 00:00:00.000”, }, { “校准日期”:“2021-01-05 00:00:00.000”, }, …等等,直到月底

用户的缺勤数据如下所示:

“缺席”:[ { “ABS_开始”:“2021-01-04 00:00:00.000”, “ABS_End”:“2021-01-05 00:00:00.000”, }, { “ABS_开始”:“2021-01-07 00:00:00.000”, “ABS_End”:“2021-01-10 00:00:00.000”, }]

所以基本上我只是检查日历上的日期是否等于或早于开始日期,是否等于或小于结束日期。简单

以下是我使用的函数部分:

// Each employee has its own calendar and absences arrays
        foreach ($employees as $employee) {

            $calendarEntries = null;
            $absences = null;

            // Here I'm getting two arrays, calendar and absences
            $calendarEntries = $employee->cdnProfile->calendarEntries;
            $absences = $employee->cdnProfile->absences;

            // Employee may not have any absences
            if ($absences->isNotEmpty()) {

                // Get each date from calendar i.e. 2021-01-01 00:00:00.000
                foreach ($calendarEntries as $calendarEntry) {

                    $absence = $absences->where('ABS_Start', '<=', $calendarEntry->CAL_Date)
                        ->where('ABS_End', '>=', $calendarEntry->CAL_Date)->first();

                    // If match the create 'test' object and add that absence to that calendar entry
                    if ($absence) {
                        $calendarEntry->test = $absence;
                    }
                }
            }
        }

        return $employees;
//每个员工都有自己的日历和缺勤数组
foreach($employees作为$employees){
$calendarEntries=null;
$absences=null;
//这里有两个数组,日历和缺席
$calendarEntries=$employee->CDN配置文件->calendarEntries;
$absences=$employee->cdn配置文件->缺席;
//员工不得缺勤
如果($absences->isNotEmpty()){
//从日历中获取每个日期,即2021-01-01 00:00:00.000
foreach($calendarEntries作为$calendarEntry){
$descence=$descences->where('ABS_Start','=',$calendarEntry->CAL_Date)->first();
//如果匹配,则创建“测试”对象并将该缺勤添加到该日历条目中
如果(缺席){
$calendarEntry->test=$Descence;
}
}
}
}
返回$employees;
我遇到的问题是,
$calendarEntry->test=$Existence;
为前几个员工获取了正确的值。之后,日期似乎被分配给了随机日历值