diff --git a/app/Actions/Schools/AssignUserToSchool.php b/app/Actions/Schools/AssignUserToSchool.php index d746d92..96f3edd 100644 --- a/app/Actions/Schools/AssignUserToSchool.php +++ b/app/Actions/Schools/AssignUserToSchool.php @@ -8,19 +8,27 @@ use App\Models\User; class AssignUserToSchool { - public function __invoke(User $user, School|int $school): void + public function __invoke(User $user, School|int|null $school): void { $this->assign($user, $school); } - public function assign(User $user, School|int $school, bool $addDomainToSchool = true): void + public function assign(User $user, School|int|null $school, bool $addDomainToSchool = true): void { + if (! User::where('id', $user->id)->exists()) { + throw new AuditionAdminException('User does not exist'); + } + if (is_int($school)) { $school = School::find($school); } - if (! User::where('id', $user->id)->exists()) { - throw new AuditionAdminException('User does not exist'); + if (is_null($school)) { + $user->update([ + 'school_id' => null, + ]); + + return; } if (is_null($school) || ! School::where('id', $school->id)->exists()) { diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 6d7ce3b..55e4238 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -64,6 +64,7 @@ class UserController extends Controller $profileUpdater->update($user, $profileData); // Deal with school assignment + dump($request->get('school_id')); if ($user->school_id != $request->get('school_id')) { $schoolAssigner($user, $request->get('school_id')); }