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

Aronaman's avatar

query

$status_id = BookStatus::where('name', 'Booked')->firstOrFail()->id;
        $check_in =$check['check_in'];
        $check_out=$check['check_out'];

$booking_id=$room->bookings()->with('individualRooms')->get();
      $booking_list=$booking_id->pluck('individual_rooms');

  $roomNeverBooking =$room->individualRooms()->whereNotIn('id',$booking_list)->get()->pluck('id','room_no');

         $roomNotReserve = $room->bookings()->with('individualRooms')->whereNotIn('bookings.book_status_id',[$status_id])

                         ->when(request(['check_in','check_out']), function($q){

                        return $q->where('bookings.check_out','=<', request('check_in'))
                              ->orWhere('bookings.check_in','>=',request('check_out'));
                               
               })->with('individualRooms')->get()->pluck('id','room_no');
            
       $result=$roomNeverBooking->merge($roomNotReserve); 

change this one line query how??????????

$roomNotReserve =$room->individualRooms()->whereNotIn('id',$booking_list)
                ->where(function ($query,$status_id){
                  $query->with('individualRooms')->whereNotIn('bookings.book_status_id',[$status_id])
                        ->when(request(['check_in','check_out']), function($q){

                          return $q->where('bookings.check_out','=<', request('check_in'))
                               ->orWhere('bookings.check_in','>=',request('check_out'));
                             });

                    })->get()->pluck('id','room_no');

        dd($roomNotReserve);// error 

edit the second query to give me the 1st output. :)

0 likes
3 replies
ahmeddabak's avatar

Please rephrase your question and explain what you want to do and what is happening, and share what error message you are receiving

Aronaman's avatar

@ahmeddabak my problem is using merge method [0=>101,1=>102] and [1=>202,3=>402]. the merge result is like this[0=>101,1=>202,3=>402], but what i need is [0=>101,1=>102,2=>202,=>3=>402]. so merge method is not working for me.

i try use array_merge($array1,$array2 and put it inside collect[] and pluck('id',room_no). same result of the merge in the collection. my question using two collections and merge them together, why dont i create 1 collection using query builder, but i make somewhere mistake

for example

->where(function ($query,$status_id){ // show me some error 1 paramete expected error...extra  

the first two collective and merge work fine expect the out put i need with pluck('id','room_no'),


edit the second query to get the first result without using merge
ahmeddabak's avatar

That should not be a problem

$array1 =  [0=>101,1=>102];
$array2 = [1=>202,3=>402];

var_dump(array_merge($array1, $array2));

//result
array(4) {
  [0]=>
  int(101)
  [1]=>
  int(102)
  [2]=>
  int(202)
  [3]=>
  int(402)
}

Test it your self here

Please or to participate in this conversation.