Laravel eloquent whereHas() is not working in with() eager loading in

Viewed 113

I am using Laravel 8.0 and I am using 'whereHas' method in 'with' method. But the condition in the 'whereHas' method is not working.

$data= static::where('capacity',">=",$adults + $children)->with(['booking_rooms'=>function($q) use($in,$out){
        $q->whereHas('booking',function($qu){
            return $qu->where('is_completed',1);
        });
        $q->where(function($qu) use($in,$out){
            return $qu->where('check_in',"<=",$in)->where('check_out','>=',$out);
        });
        $q->orWhere(function($qu) use($in,$out){
            return $qu->where('check_in',">=",$in)->where('check_out','<=',$out);
        });
        $q->orWhere(function($qu) use($in,$out){
            return $qu->where('check_in',"<=",$in)->where('check_out',">=",$in)->where('check_out','<=',$out);
        });
        $q->orWhere(function($qu) use($in,$out){
            return $qu->where('check_in',">=",$in)->where('check_in',"<=",$out)->where('check_out','>=',$out);
        });
        return $q;
    }])->with(['room_holds'=>function($q) use($in,$out,$key){
        $q->where(function($q) use($in,$out){
            $q->where(function($qu) use($in,$out){
                return $qu->where('check_in',"<=",$in)->where('check_out','>=',$out);
            });
            $q->orWhere(function($qu) use($in,$out){
                return $qu->where('check_in',">=",$in)->where('check_out','<=',$out);
            });
            $q->orWhere(function($qu) use($in,$out){
                return $qu->where('check_in',"<=",$in)->where('check_out',">=",$in)->where('check_out','<=',$out);
            });
            $q->orWhere(function($qu) use($in,$out){
                return $qu->where('check_in',">=",$in)->where('check_in',"<=",$out)->where('check_out','>=',$out);
            });
        });
        $q->where('till',">=",Carbon::now())->where("session_id","<>",$key);
        return $q;
    }])->get();

How can I make the condition affective in 'whereHas' method?

0 Answers
Related