assign($user, $school); } public function assign(User $user, School $school, bool $addDomainToSchool = true): void { if (! User::where('id', $user->id)->exists()) { throw new AuditionAdminException('User does not exist'); } if (! School::where('id', $school->id)->exists()) { throw new AuditionAdminException('School does not exist'); } $domainRecorder = app(AddSchoolEmailDomain::class); if ($addDomainToSchool) { $domainRecorder($school, $user->emailDomain()); } $user->update([ 'school_id' => $school->id, ]); } }