Skip to content

Commit 70ea48d

Browse files
committed
Fix issue with between scope.
Laravel 11.28 changed the behaviour when using arrays in orWhere. This commit uses more explicit syntax and fixes the issue.
1 parent dd54501 commit 70ea48d

2 files changed

Lines changed: 2359 additions & 1172 deletions

File tree

app/Models/Booking.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ protected function getIsCheckedOutAttribute(): bool
205205
public function scopeBetween(Builder $query, $start, $end): Builder
206206
{
207207
// Make sure dates are Carbon objects.
208-
$start = Carbon::parse((is_numeric($start) ? '@' : '').$start);
209-
$end = Carbon::parse((is_numeric($end) ? '@' : '').$end);
208+
$start = is_numeric($start) ? Carbon::createFromTimestamp($start) : Carbon::parse($start);
209+
$end = is_numeric($end) ? Carbon::createFromTimestamp($end) : Carbon::parse($end);
210210

211211
// Add second and subtract second to allow booking to start or end at same time.
212212
$startTime = $start->copy()->addSecond();
@@ -216,15 +216,17 @@ public function scopeBetween(Builder $query, $start, $end): Builder
216216
return $query->where(function ($query) use ($startTime, $endTime) {
217217
$query
218218
// Exactly the same time as given interval.
219-
->where([
220-
['start_time', $startTime->copy()->subSecond()],
221-
['end_time', $endTime->copy()->addSecond()],
222-
])
219+
->where(function ($query) use ($startTime, $endTime) {
220+
$query
221+
->where('start_time', '=', $startTime->copy()->subSecond())
222+
->where('end_time', '=', $endTime->copy()->addSecond());
223+
})
223224
// Start before and end after interval.
224-
->orWhere([
225-
['start_time', '<', $startTime],
226-
['end_time', '>', $endTime],
227-
])
225+
->orWhere(function ($query) use ($startTime, $endTime) {
226+
$query
227+
->where('start_time', '<', $startTime)
228+
->where('end_time', '>', $endTime);
229+
})
228230
// Start in interval.
229231
->orWhereBetween('start_time', [$startTime, $endTime])
230232
// End in interval.

0 commit comments

Comments
 (0)