UpdateBasicInfoRequest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Http\Requests\Coach;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. /**
  5. * 技师基础信息更新请求验证
  6. */
  7. class UpdateBasicInfoRequest extends FormRequest
  8. {
  9. public function rules(): array
  10. {
  11. $rules = [
  12. 'nickname' => 'nullable|string|min:2|max:20',
  13. 'gender' => 'nullable|integer|in:1,2',
  14. 'mobile' => [
  15. 'nullable',
  16. 'string',
  17. 'size:11',
  18. 'regex:/^1[3-9]\d{9}$/',
  19. ],
  20. ];
  21. // 如果提交了手机号,则验证码必填
  22. if ($this->has('mobile')) {
  23. $rules['code'] = 'required|string|size:6';
  24. }
  25. return $rules;
  26. }
  27. public function messages(): array
  28. {
  29. return [
  30. 'nickname.string' => '昵称必须是字符串',
  31. 'nickname.min' => '昵称不能少于2个字符',
  32. 'nickname.max' => '昵称不能超过20个字符',
  33. 'gender.integer' => '性别必须是整数',
  34. 'gender.in' => '性别只能是1(男)或2(女)',
  35. 'mobile.size' => '手机号必须是11位',
  36. 'mobile.regex' => '手机号格式不正确',
  37. 'code.required' => '验证码不能为空',
  38. 'code.size' => '验证码必须是6位',
  39. ];
  40. }
  41. }