ModelRelatedsValidator.php 619 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace UCore\Validator;
  3. use UCore\Validator;
  4. use App\Models\Hp\User;
  5. /**
  6. * 关联查询,批量
  7. *
  8. */
  9. class ModelRelatedsValidator extends Validator
  10. {
  11. public function validate(mixed $value, array $data): bool
  12. {
  13. $list = $this->args;
  14. foreach ($list as $modelClass => $field){
  15. /**
  16. * @var \Illuminate\Database\Eloquent\Builder $query
  17. */
  18. $query = $modelClass::query();
  19. $re = $query->whereIn($field,$value)->first();
  20. if($re){
  21. return false;
  22. }
  23. }
  24. return false;
  25. }
  26. }