Aronaman
1 month ago
172
3
Laravel

query

Posted 1 month ago by Aronaman
$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. :)

Please sign in or create an account to participate in this conversation.