CreateRequest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Http\Requests\Client\Comment;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. class CreateRequest extends FormRequest
  5. {
  6. public function authorize(): bool
  7. {
  8. return true;
  9. }
  10. public function rules(): array
  11. {
  12. return [
  13. 'order_id' => [
  14. 'required',
  15. 'integer',
  16. 'exists:order,id',
  17. ],
  18. 'score' => [
  19. 'required',
  20. 'integer',
  21. 'min:1',
  22. 'max:5',
  23. ],
  24. 'content' => [
  25. 'nullable',
  26. 'string',
  27. 'max:500',
  28. ],
  29. 'images' => [
  30. 'nullable',
  31. 'array',
  32. 'max:9',
  33. ],
  34. 'images.*' => [
  35. 'required',
  36. 'string',
  37. 'max:255',
  38. ],
  39. 'is_anonymous' => [
  40. 'nullable',
  41. 'boolean',
  42. ],
  43. 'tag_ids' => [
  44. 'nullable',
  45. 'array',
  46. 'max:5',
  47. ],
  48. 'tag_ids.*' => [
  49. 'required',
  50. 'integer',
  51. 'exists:coach_comment_tags,id',
  52. ],
  53. ];
  54. }
  55. public function messages(): array
  56. {
  57. return [
  58. 'order_id.required' => '订单ID不能为空',
  59. 'order_id.integer' => '订单ID必须是整数',
  60. 'order_id.exists' => '订单不存在',
  61. 'score.required' => '评分不能为空',
  62. 'score.integer' => '评分必须是整数',
  63. 'score.min' => '评分最小为1分',
  64. 'score.max' => '评分最大为5分',
  65. 'content.max' => '评价内容不能超过500个字符',
  66. 'images.array' => '图片必须是数组',
  67. 'images.max' => '最多上传9张图片',
  68. 'images.*.required' => '图片不能为空',
  69. 'images.*.string' => '图片必须是字符串',
  70. 'images.*.max' => '图片地址不能超过255个字符',
  71. 'is_anonymous.boolean' => '是否匿名必须是布尔值',
  72. 'tag_ids.array' => '标签必须是数组',
  73. 'tag_ids.max' => '最多选择5个标签',
  74. 'tag_ids.*.required' => '标签ID不能为空',
  75. 'tag_ids.*.integer' => '标签ID必须是整数',
  76. 'tag_ids.*.exists' => '标签不存在',
  77. ];
  78. }
  79. }