/** * Get all users with role of company representative, which company/companies belong to the given industry. * * @param Industry $industry * * @return Builder */ public function whereCompaniesIndustry(Industry $industry) { return User::whereHas('companies.industry', function (Builder $query) use($industry) { $query->where('industries.id', $industry->id); }); }