this repo has no description
at master 951 B view raw
1<?php 2 3namespace App\Models; 4 5use Carbon\Carbon; 6use Illuminate\Database\Eloquent\Model; 7use Illuminate\Support\Facades\Auth; 8 9class UserAttendance extends Model 10{ 11 protected $fillable = [ 12 'user_id', 13 'check_in_at', 14 'check_out_at', 15 'latitude', 16 'longitude', 17 'created_at', 18 'updated_at' 19 ]; 20 21 protected $casts = [ 22 'check_in_at' => 'datetime', 23 'check_out_at' => 'datetime', 24 ]; 25 26 public static function doesOverlap(Carbon $from, Carbon $to, int|null $excludeId) 27 { 28 $countA = UserAttendance::where('id', '!=', $excludeId)->where('user_id', Auth::user()->id)->where('check_in_at', '<', $from)->where('check_out_at', '>', $from)->count(); 29 $countB = UserAttendance::where('id', '!=', $excludeId)->where('user_id', Auth::user()->id)->where('check_in_at', '<', $to)->where('check_out_at', '>', $to)->count(); 30 31 return $countA + $countB > 0; 32 } 33}