FormdemoRequest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App\Http\Requests;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. use Illuminate\Http\Request;
  5. class FormdemoRequest extends FormRequest
  6. {
  7. /**
  8. * Determine if the user is authorized to make this request.
  9. *
  10. * @return bool
  11. */
  12. public function authorize()
  13. {
  14. return true;
  15. }
  16. /**
  17. * Get the validation rules that apply to the request.
  18. *
  19. * @return array
  20. */
  21. public function demo(Request $request){
  22. return $request->pan;
  23. }
  24. public function rules(Request $request)
  25. {
  26. switch ($request->pan) {
  27. case '1':
  28. return [
  29. 'firstname' => 'required|max:20|regex:/\p{Han}/u',
  30. 'gj_num' => 'required|max:50|alpha_dash',
  31. 'phone' => 'required|regex:/^1[345789][0-9]{9}$/',
  32. 'note' => 'max:50',
  33. ];
  34. case '0':
  35. return [
  36. 'firstname' => 'required|max:20|regex:/\p{Han}/u',
  37. 'gj_num' => 'required|max:50|alpha_dash',
  38. 'hk-name' => 'required|max:20|regex:/\p{Han}/u',
  39. 'hk-date' => 'nullable|date_format:"Y-m-d"',
  40. 'hk-num' => 'required|min:0.01',
  41. 'title' => 'nullable|max:50|regex:/\p{Han}/u',
  42. 'ns-name' => 'required|max:20|regex:/\p{Han}/u',
  43. 'ns-num' => ['required'],
  44. 'ns-hang' => ['nullable', 'regex:/\p{Han}/u'],
  45. 'ns-account' => ['nullable', 'regex:/^([1-9])(\d|\d|\d)$/'],
  46. 'sj-name' => ['required', 'max:20', 'regex:/\p{Han}/u'],
  47. 'phone' => 'required|regex:/^1[345789][0-9]{9}$/',
  48. 'note' => 'max:50',
  49. ];
  50. default:
  51. return [];
  52. }
  53. }
  54. public function messages()
  55. {
  56. return [
  57. 'required' => '这是一个必填项哦!',
  58. 'alpha_dash' => '格式不正确哦',
  59. 'firstname.regex' => '请输入汉字',
  60. 'firstname.max' => '最大只能20个字',
  61. 'gj_num.max' => '最多只能50个字',
  62. 'hk-date.date_format' => '时间格式错误',
  63. // 'hk-num.numeric' => '请输入数字',
  64. 'title.max' => '最多输入50个字',
  65. 'title.regex' => '包含非法字符(请输入汉字)',
  66. 'ns-name.max' => '只能输入20个字哦',
  67. 'ns-name.regex' => '含有非法字符(请输入汉字)',
  68. // 'ns-num.regex' => '纳税人识别号格式出错!',
  69. 'ns-hang.regex' => '银行名称填写出错',
  70. 'ns-account.regex' => '银行账号填写出错!请检查',
  71. 'sj-name.max' => '只能输入20个字哦',
  72. 'sj-name.regex' => '包含非法字符(请填写汉字)',
  73. 'note.max' => '最好只能留言50个字哦',
  74. 'phone.regex' => '手机号码格式错误',
  75. ];
  76. }
  77. /*
  78. * 验证规则二
  79. *
  80. * */
  81. public function ruless()
  82. {
  83. }
  84. /*
  85. * 自定义错误信息二
  86. */
  87. public function messagess()
  88. {
  89. }
  90. }