'How to check a condition with nested relation in laravel

I have a problem while getting data when using whereHas.

Addons::with(['addons_details','group_addons.group_addon_details'])->when($id,function($query) use ($id){
            $query->whereHas('group_addons',function($query) use ($id){
                $query->where('group_id',$id);
            });
        })
        ->orderBy('id','desc')->get()

Using this query i will get addons model details which exist in group_addons. I want to get all rows in Addons model.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source