Home > Blockchain >  Check car if available between 2 date laravel
Check car if available between 2 date laravel

Time:01-04

App For Rental Car : I need check car if available between 2 date and check quantity ("column name : qty"), There is no need for a car more than the available number of cars (number cars booking < QTY car ) When change number 3 in the name of the column ('qty') does not work. Query From Url : $PickupStartDate,$DropEndDate;

Car::withCount('reservation')->having('reservation_count', '<', 3)->get();

Tables :

Cars ID | name | price | qty|

Reservations ID | start_date | end_date | days | start_place | return_place | car_id |

check if car available for rental check we have a car between date

CodePudding user response:

$start_date = $PickupStartDate;
$end_date = $DropEndDate;

$cars = Car::with(['reservations' => function($query) use ($start_date, $end_date) {
    $query->where('start_date', '<=', $end_date)
          ->where('end_date', '>=', $start_date);
}])->having(3, '<', 'reservations_count')->get();

Try this

CodePudding user response:

Solution :

    $start_date= $filters['StartDate'];
    $end_date= $filters['EndDate'];
    $query->withCount(['reservation' => function($query) use ($start_date, $end_date) {
        $query->where('start_date', '<=', $start_date)
        ->where('end_date', '>=', $end_date)
        ->orWhere('end_date', '>', $start_date);
    }])

in code Check Car.qty< car.reservation_count

  • Related