/** * Check to make sure at lease one role is being applied or deactivate user * @param $user * @param $roles * @throws UserNeedsRolesException */ private function validateRoleAmount($user, $roles) { //Validate that there's at least one role chosen, placing this here so //at lease the user can be updated first, if this fails the roles will be //kept the same as before the user was updated if (count($roles) == 0) { //Deactivate user $user->status = 0; $user->save(); $exception = new UserNeedsRolesException(); $exception->setValidationErrors('You must choose at lease one role. User has been created but deactivated.'); //Grab the user id in the controller $exception->setUserID($user->id); throw $exception; } }
/** * Check to make sure at lease one role is being applied or deactivate user * * @param $user * @param $roles * @throws UserNeedsRolesException */ private function validateRoleAmount($user, $roles) { //Validate that there's at least one role chosen, placing this here so //at lease the user can be updated first, if this fails the roles will be //kept the same as before the user was updated if (count($roles) == 0) { //Deactivate user $user->status = 0; $user->save(); $exception = new UserNeedsRolesException(); $exception->setValidationErrors(trans('exceptions.backend.access.users.role_needed_create')); //Grab the user id in the controller $exception->setUserID($user->id); throw $exception; } }