blob: 2adecbc3e3761f50676716c4bdd96fa9ee913c75 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
<?php
namespace App\Services;
use App\Models\Appointment;
class AppointmentService
{
public static function appointmentTimeOverlap(array $data, $id = null): bool
{
$query = Appointment::where('company_id', $data['company_id'])
->where(function ($query) use ($data) {
$query->whereBetween('time_start', [$data['time_start'], $data['time_end']])
->orWhereBetween('time_end', [$data['time_start'], $data['time_end']])
->orWhere(function ($query_) use ($data) {
$query_->where('time_start', '<=', $data['time_start'])
->where('time_end', '>=', $data['time_end']);
});
});
if ($id) {
$query->where('id', '!=', $id);
}
return $query->exists();
}
}
|