UserRequest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Http\Requests;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. use Illuminate\Support\Facades\Auth;
  5. class UserRequest extends Request
  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 rules()
  22. {
  23. return [
  24. /*'name' => 'required|between:3,25|regex:/^[A-Za-z0-9\-\_]+$/|unique:users,name,' . Auth::id(),*/
  25. 'name' => 'required|between:2,25|unique:users,name,' . Auth::id(),
  26. 'email' => 'required|email|unique:users,email,' . Auth::id(),
  27. 'introduction' => 'max:80',
  28. 'github_name' => 'max:80',
  29. 'real_name' => 'max:20',
  30. 'city' => 'max:40',
  31. 'company' => 'max:80',
  32. 'jobtitle' => 'max:80',
  33. 'personal_website' => 'max:120',
  34. 'signature' => 'max:255',
  35. 'avatar' => 'mimes:jpeg,bmp,png,gif|dimensions:min_width=208,min_height=208',
  36. 'wechat_qrcode' => 'mimes:jpeg,bmp,png,gif',
  37. 'payment_qrcode' => 'mimes:jpeg,bmp,png,gif',
  38. 'gender' => 'in:male,female',
  39. ];
  40. }
  41. public function messages()
  42. {
  43. return [
  44. 'name.unique' => '用户名已被占用,请重新填写',
  45. /*'name.regex' => '用户名只支持英文、数字、横杠和下划线。',*/
  46. 'name.between' => '用户名必须介于 2 - 25 个字符之间。',
  47. 'name.required' => '用户名不能为空。',
  48. 'email.required' => '邮箱不能为空',
  49. 'email.email' => '请填写正确的邮箱',
  50. 'email.unique' => '邮箱已被注册,请重新填写',
  51. 'avatar.mimes' =>'头像必须是 jpeg, bmp, png, gif 格式的图片',
  52. 'wechat_qrcode.mimes' =>'微信账号二维码必须是 jpeg, bmp, png, gif 格式的图片',
  53. 'payment_qrcode.mimes' =>'支付二维码必须是 jpeg, bmp, png, gif 格式的图片',
  54. 'avatar.dimensions' => '图片的清晰度不够,宽和高需要 208px 以上',
  55. 'introduction.max' => '个人简介最多 80 个字符。',
  56. 'real_name.max' => '真实姓名最多 20 个字符。',
  57. 'city.max' => '城市最多 40 个字符。',
  58. 'company.max' => '公司或组织名称最多 80 个字符。',
  59. 'jobtitle.max' => '职位头衔最多 80 个字符。',
  60. 'personal_website.max' => '个人网站最多 120 个字符。',
  61. 'signature.max' => '署名最多 255 个字符。',
  62. ];
  63. }
  64. }