dilfdo
233
1
Laravel

laravel time overlap checking issue with Query builder...

Posted 3 years ago by dilfdo

please help me to fi this. i want to check shift time overlapping when user adding or editing shit time

here is example of table where current shifts times

1 )shift:1 start_time 04:00 end_time 05:00
2)shift 2  start_time 09:00 end_time 11:00

```

when i update shit 2 to start_time 04:20 end_time 04:30   it should give error since its overlapping with shift 1

im checking whether shift overlapped by below query
``
 $shiftData = Shifts::where('time_sheet_id', '=', $timesheet_id->id)
                        ->where('user_id', '=', $driver_id->id)
                        ->where('role_id', '=', 1)
                        ->whereBetween('shift_start_time', array($shift_start , $shift_end))
                        ->whereBetween('shift_end_time' , array($shift_start , $shift_end))
                        ->count();


but with this query i still can add start_time 04:20 end_time 04:30  value even it overlapp ? how to change my query to check
inbetween values as well ? pls advice 

                    

Please sign in or create an account to participate in this conversation.