Wednesday, March 15, 2017

Please help me understand this function

I'm trying to learn this tutorial In the function createReservation() function

   while (strtotime($date) < strtotime($end_dt)) {

    $room_calendar = RoomCalendar::where('day','=',$date)
        ->where('room_type_id','=',$room_info['id'])->first();

    $night =  ReservationNight::create();
    $night->day=$date;

    $night->rate=$room_calendar->rate;
    $night->room_type_id=$room_info['id'];
    $night->reservation_id=$reservation->id;

    $room_calendar->availability--;
    $room_calendar->reservations++;

    $room_calendar->save();
    $night->save();

    $date = date ("Y-m-d", strtotime("+1 day", strtotime($date)));

}

$room_calendar->availability doesn't have a default value. So wouldn't it go to negative when it's decremented?



via Sai Krishna

Advertisement