$noOverlappingClocks = fn(Get $get): Closure => function (string $attribute, $value, Closure $fail) use ($get) {
$userId = $get('user_id');
$clockIn = $get('clock_in');
$clockOut = $get('clock_out');
if ($clockIn && $clockOut) {
$overlap = TimeLog::query()
->where('user_id', $userId)
->where(function ($query) use ($clockIn, $clockOut) {
$query->whereBetween('clock_in', [$clockIn, $clockOut])
->orWhereBetween('clock_out', [$clockIn, $clockOut])
->orWhere(function ($query) use ($clockIn, $clockOut) {
$query->where('clock_in', '<', $clockIn)
->where('clock_out', '>', $clockOut);
});
})
->exists();
if ($overlap) {
$fail("The provided time log overlaps with an existing entry.");
}
}
};
$noOverlappingClocks = fn(Get $get): Closure => function (string $attribute, $value, Closure $fail) use ($get) {
$userId = $get('user_id');
$clockIn = $get('clock_in');
$clockOut = $get('clock_out');
if ($clockIn && $clockOut) {
$overlap = TimeLog::query()
->where('user_id', $userId)
->where(function ($query) use ($clockIn, $clockOut) {
$query->whereBetween('clock_in', [$clockIn, $clockOut])
->orWhereBetween('clock_out', [$clockIn, $clockOut])
->orWhere(function ($query) use ($clockIn, $clockOut) {
$query->where('clock_in', '<', $clockIn)
->where('clock_out', '>', $clockOut);
});
})
->exists();
if ($overlap) {
$fail("The provided time log overlaps with an existing entry.");
}
}
};