// SYSTEM PANEL //
[ROOT]
/
mnt
/
pleskStorage
/
vhosts
/
kodsolutions.net
/
subdomains
/
go-rent.kodsolutions.net
/
app
/
Services
/
Booking
[ PARENT ]
EDIT :: CarAvailabilityService.php
<?php namespace App\Services\Booking; use Exception; use App\Enums\OrderStatus; class CarAvailabilityService { public function checkCarAvailability(\App\Models\Car\Car $car, $pickupDate, $dropoffDate): void { $existingBooking = \App\Models\Booking\Order::where('car_id', $car->id) ->whereNotIn('status', [OrderStatus::COMPLETED, OrderStatus::CANCELLED]) ->where(function ($query) use ($pickupDate, $dropoffDate) { $query->whereBetween('pickup_date', [$pickupDate, $dropoffDate]) ->orWhereBetween('dropoff_date', [$pickupDate, $dropoffDate]) ->orWhere(function ($subQuery) use ($pickupDate, $dropoffDate) { $subQuery->where('pickup_date', '<=', $dropoffDate) ->where('dropoff_date', '>=', $pickupDate); }); }) ->exists(); if ($existingBooking) { throw new Exception("The car is not available now."); } } }
SAVE
CANCEL