diff --git a/app/Allocator/Stand/AbstractArrivalStandAllocator.php b/app/Allocator/Stand/AbstractArrivalStandAllocator.php index 33267e5bd..35efcb1e6 100644 --- a/app/Allocator/Stand/AbstractArrivalStandAllocator.php +++ b/app/Allocator/Stand/AbstractArrivalStandAllocator.php @@ -5,6 +5,7 @@ use App\Models\Aircraft\Aircraft; use App\Models\Stand\Stand; use App\Models\Vatsim\NetworkAircraft; +use Carbon\Carbon; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Query\JoinClause; @@ -59,7 +60,17 @@ private function applyBaseOrderingToStandsQuery(Builder $query, NetworkAircraft ->leftJoin('stand_requests as other_stand_requests', function (JoinClause $join) use ($aircraft) { // Prefer stands that haven't been requested by someone else $join->on('stands.id', '=', 'other_stand_requests.stand_id') - ->on('other_stand_requests.user_id', '<>', $join->raw($aircraft->cid)); + ->on('other_stand_requests.user_id', '<>', $join->raw($aircraft->cid)) + ->on( + 'other_stand_requests.requested_time', + '>', + $join->raw( + sprintf( + '\'%s\'', + Carbon::now() + ) + ) + ); }) ->orderByRaw('other_stand_requests.id IS NULL') ->inRandomOrder();