CropPickValidation.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Module\Farm\Validations;
  3. use UCore\Validation\BaseValidation;
  4. /**
  5. * 作物摘取验证类
  6. *
  7. * @property int $pickerId 摘取者ID
  8. * @property int $cropId 作物ID
  9. * @property int $pickAmount 摘取数量
  10. * @property string $pickSource 摘取来源
  11. * @property int|null $sourceId 来源ID(可选)
  12. */
  13. class CropPickValidation extends BaseValidation
  14. {
  15. public int $pickerId;
  16. public int $cropId;
  17. public int $pickAmount;
  18. public string $pickSource;
  19. public ?int $sourceId = null;
  20. /**
  21. * 获取验证规则
  22. *
  23. * @return array
  24. */
  25. public function rules(): array
  26. {
  27. return [
  28. 'pickerId' => 'required|integer|min:1',
  29. 'cropId' => 'required|integer|min:1',
  30. 'pickAmount' => 'required|integer|min:1',
  31. 'pickSource' => 'required|string|max:50',
  32. 'sourceId' => 'nullable|integer|min:1',
  33. ];
  34. }
  35. /**
  36. * 获取验证错误消息
  37. *
  38. * @return array
  39. */
  40. public function messages(): array
  41. {
  42. return [
  43. 'pickerId.required' => '摘取者ID不能为空',
  44. 'pickerId.integer' => '摘取者ID必须为整数',
  45. 'pickerId.min' => '摘取者ID必须大于0',
  46. 'cropId.required' => '作物ID不能为空',
  47. 'cropId.integer' => '作物ID必须为整数',
  48. 'cropId.min' => '作物ID必须大于0',
  49. 'pickAmount.required' => '摘取数量不能为空',
  50. 'pickAmount.integer' => '摘取数量必须为整数',
  51. 'pickAmount.min' => '摘取数量必须大于0',
  52. 'pickSource.required' => '摘取来源不能为空',
  53. 'pickSource.string' => '摘取来源必须为字符串',
  54. 'pickSource.max' => '摘取来源长度不能超过50个字符',
  55. 'sourceId.integer' => '来源ID必须为整数',
  56. 'sourceId.min' => '来源ID必须大于0',
  57. ];
  58. }
  59. }