BankValidator.php 1.6 KB

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