我在数据库的设置页面中创建了一个复选框,它工作正常,打开和关闭都有效。
现在我想如果它关闭,这个条件应该起作用,如果打开它不应该起作用。
public function index()
{
if (permission::permitted('dashboard')=='fail'){ return redirect()->route('denied'); }
// Updated Code of Auto Clockout Start
**$clockedInUsers = DB::table('people_attendance')
->whereNull('timeout')
->get();
foreach ($clockedInUsers as $user) {
$timeIn = Carbon::parse($user->timein);
$currentTime = Carbon::now();
// Get the first clock-in time of the day for the user
$firstClockIn = DB::table('people_attendance')
->where('employee', $user->employee)
->where('date', $timeIn->format('Y-m-d'))
->orderBy('timein')
->first();
if (!$firstClockIn) {
continue; // Skip users with no clock-ins for the day
}
$firstClockInTime = Carbon::parse($firstClockIn->timein);
$clockInCount = DB::table('people_attendance')
->where('employee', $user->employee)
->where('date', $timeIn->format('Y-m-d'))
->count();
// Define different auto-clockout times and totalhours based on the clock-in count
$autoClockOutIntervals = [
1 => ['minutes' => 330, 'totalhours' => '5.30'],
2 => ['minutes' => 720, 'totalhours' => '12'],
3 => ['minutes' => 720, 'totalhours' => '12'],
];
if (isset($autoClockOutIntervals[$clockInCount])) {
$intervalData = $autoClockOutIntervals[$clockInCount];
$autoClockOutMinutes = $intervalData['minutes'];
$autoClockOutTime = $firstClockInTime->copy()->addMinutes($autoClockOutMinutes);
if ($currentTime >= $autoClockOutTime) {
$newTimeout = $firstClockInTime->addMinutes($autoClockOutMinutes)->format('Y-m-d H:i:s');
DB::table('people_attendance')
->where('id', $user->id)
->update([
'timeout' => $newTimeout,
'totalhours' => $intervalData['totalhours']
]);
}
}
}
//更新自动下班结束代码**
我不知道我到底应该做什么才能在那里提出条件。关于索引函数。
如果提交表单时未选中复选框,则复选框值将不会在请求中发送。您可以使用这样的 if 条件:
if(isset($request->input(‘checkbox’))){
// code
} else{
// code
}