builder->whereHas('users', function (Builder $query) use ($val) { $query->where('mobile', 'like', "%{$val}%"); }); } protected function nickname($val) { $this->builder->whereHas('users', function (Builder $query) use ($val) { $query->where('nickname', 'like', "%{$val}%"); }); } protected function mobileNickname($val){ $this->builder->whereHas('users', function (Builder $query) use ($val) { $query->where('mobile', 'like', "%{$val}%") ->Orwhere('nickname', 'like', "%{$val}%"); }); } }