ApplyCoachRequest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace App\Http\Requests\Client\User;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. class ApplyCoachRequest extends FormRequest
  5. {
  6. public function authorize(): bool
  7. {
  8. return true;
  9. }
  10. public function rules(): array
  11. {
  12. return [
  13. 'age' => [
  14. 'required',
  15. 'integer',
  16. 'between:18,60',
  17. ],
  18. 'mobile' => [
  19. 'required',
  20. 'string',
  21. 'size:11',
  22. 'regex:/^1[3-9]\d{9}$/',
  23. ],
  24. 'gender' => [
  25. 'required',
  26. 'integer',
  27. 'in:1,2',
  28. ],
  29. 'work_years' => [
  30. 'required',
  31. 'integer',
  32. 'min:0',
  33. 'max:50',
  34. ],
  35. 'intention_city' => [
  36. 'required',
  37. 'string',
  38. 'max:50',
  39. ],
  40. 'life_photos' => [
  41. 'required',
  42. 'array',
  43. 'min:1',
  44. 'max:6',
  45. ],
  46. 'life_photos.*' => [
  47. 'required',
  48. 'string',
  49. 'max:2048', // 限制单张图片大小
  50. ],
  51. 'introduction' => [
  52. 'nullable',
  53. 'string',
  54. 'max:1000',
  55. ],
  56. ];
  57. }
  58. public function messages(): array
  59. {
  60. return [
  61. 'age.required' => '年龄不能为空',
  62. 'age.integer' => '年龄必须是整数',
  63. 'age.between' => '年龄必须在18-60岁之间',
  64. 'mobile.required' => '手机号不能为空',
  65. 'mobile.size' => '手机号必须是11位',
  66. 'mobile.regex' => '手机号格式不正确',
  67. 'gender.required' => '性别不能为空',
  68. 'gender.in' => '性别只能是1(男)或2(女)',
  69. 'work_years.required' => '工作年限不能为空',
  70. 'work_years.integer' => '工作年限必须是整数',
  71. 'work_years.min' => '工作年限不能小于0年',
  72. 'work_years.max' => '工作年限不能超过50年',
  73. 'intention_city.required' => '意向城市不能为空',
  74. 'intention_city.max' => '意向城市不能超过50个字符',
  75. 'life_photos.required' => '生活照片不能为空',
  76. 'life_photos.array' => '生活照片必须是数组',
  77. 'life_photos.min' => '至少上传1张生活照片',
  78. 'life_photos.max' => '最多上传6张生活照片',
  79. 'life_photos.*.required' => '生活照片不能为空',
  80. 'life_photos.*.string' => '生活照片格式不正确',
  81. 'life_photos.*.max' => '单张照片大小不能超过2MB',
  82. 'introduction.max' => '个人简介不能超过1000字',
  83. ];
  84. }
  85. }