UsernameNtValidator.php 479 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace App\Module\User\Validator;
  3. use App\Module\User\Models\User;
  4. use UCore\Validator;
  5. /**
  6. * 用户名重复检测,存在false
  7. * 不存在true
  8. *
  9. */
  10. class UsernameNtValidator extends Validator
  11. {
  12. public function validate($value, array $data): bool
  13. {
  14. $user = User::query()->where('username','=',$value)->first();
  15. if ($user) {
  16. $this->validation->user = $user;
  17. return false;
  18. }
  19. return true;
  20. }
  21. }