diff --git a/app/Services/EventCalendarService.php b/app/Services/EventCalendarService.php index 9c79c90..5f83b96 100644 --- a/app/Services/EventCalendarService.php +++ b/app/Services/EventCalendarService.php @@ -105,18 +105,28 @@ class EventCalendarService extends BaseService { try { DB::beginTransaction(); - $existsWhere = [ - ['pattern_id', '=', $data['pattern_id']], - ['id', '<>', $id] - ]; - if (EventCalendar::query()->where($existsWhere)->whereIn( - 'status', - [0, 1] - )->exists() + if (isset($data['status']) && $data['status'] == 0 + && isset($data['start_time']) ) { - throw new Exception( - __('service.event_calendar.pattern_exists') - ); + $start_time = $data['start_time']; + $existsWhere = [ + ['pattern_id', '=', $data['pattern_id']], + ['id', '<>', $id] + ]; + if (EventCalendar::query()->where($existsWhere)->whereIn( + 'status', + [0, 1] + ) + ->where(function ($query) use ($start_time) { + $query->whereRaw( + "'{$start_time}' BETWEEN start_time AND end_time" + ); + })->exists() + ) { + throw new Exception( + __('service.event_calendar.pattern_exists') + ); + } } $model = EventCalendar::query()->findOrFail($id); $oldValues = $model->toArray();