whereHas('promote', function ($query) use ($promote) { $query->ofParent($promote)->orWhere('promote_id', $promote->id); }); } else { $query->where('promote_id', $promote->id); } return $query; } }