Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Aronaman's avatar

query filter

d/m/y . ... and 02/01/20 -03/01/20 room 101 booked.

14/01/20-21/01/20 101 and 201 booked.

my question is on 03/01/20 - 14/01/20 both 101 and 201 available, but in my query getting 101, 101, 201, is there is other way ???

$roomNotReserve =$room->bookings()
                  ->whereNotIn('book_status_id',$statusCollect)
                  ->where(function($q2) use ($check_in, $check_out) {

                        $q2->where('check_in','>=',$check_out) 
                           ->orWhere('check_out','<=',$check_in);
                    })->with('individualRooms')->get()->pluck('individualRooms')->toArray();
 $q2->where('check_in','>=',$check_out) 
                           ->orWhere('check_out','<=',$check_in);

not consider the repetition!! same room booked on the different dates are all show up.

0 likes
3 replies
a4ashraf's avatar

Hi @aronaman

Try this one

$q2->where('check_in','>=',$check_out) 
                           ->Where('check_out','<=',$check_in);

can you show here your database schema

Aronaman's avatar
 })->with('individualRooms')->get()->pluck('individualRooms')->toArray();

out put

array:2 [▼
  0 => array:1 [▼
    0 => array:8 [▶]
  ]
  1 => array:2 [▼
    0 => array:8 [▶]
    1 => array:8 [▶]
  ]
]

using first

 })->with('individualRooms')->get()->pluck('individualRooms')->first()->toArray();

result

 0 => array:8 [▼
    "id" => 3
    "room_id" => 1
    "room_no" => 202
    "room_floor" => null
    "created_at" => "2020-01-26 16:02:39"
    "updated_at" => "2020-01-26 16:02:39"
    "deleted_at" => null
    "pivot" => array:2 [▶]
  ]
]

working fine, but only the "first array" show up to access room_no.

my question is how can i get all array and access "room_no" get list like pluck('id','room_no');

Please or to participate in this conversation.