BankValidator.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Http\Validator;
  3. class BankValidator extends BaseValidator
  4. {
  5. // 当前模型所有验证规则
  6. public static $rules = [
  7. 'id' => 'required',
  8. 'account' => 'required|min:15|max:30',
  9. 'account_name' => 'min:2|max:50',
  10. 'account_remark' => 'required|min:2|max:30',
  11. 'status' => 'required',
  12. ];
  13. public static $msgs = [
  14. 'required' => ':attribute不能为空',
  15. 'string' => ':attribute必须是字符串',
  16. 'min' => ':attribute长度不能小于:min位',
  17. 'max' => ':attribute长度不能大于:max位',
  18. 'exists' => ':attribute不存在',
  19. 'rule' => ':attribute格式不正确',
  20. 'mobile' => ':attribute格式不正确',
  21. ];
  22. // 当前模型所有验证字段
  23. public static $fields = [
  24. 'id' => 'ID',
  25. 'realname' => '收款人姓名',
  26. 'account_name' => '开户行',
  27. 'account' => '银行卡号',
  28. 'account_remark' => '开户支行',
  29. ];
  30. // 当前模型所有验证场景
  31. public static $scenes = [
  32. 'save'=> ['account_name','account','account_remark'],
  33. 'del'=> ['id'],
  34. ];
  35. /**
  36. * 验证
  37. * @param $request
  38. * @param string $scene
  39. * @return int|mixed
  40. */
  41. public static function check($request, $scene=''){
  42. $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
  43. return $validator->checkParams($request, $scene);
  44. }
  45. }