validate.stub 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace {{namespace_start}}validate{{namespace_end}};
  3. use think\Validate;
  4. /**
  5. * {{menu_name}}验证器
  6. */
  7. class {{class_name}}Validate extends Validate
  8. {
  9. /**
  10. * 定义验证规则
  11. */
  12. protected $rule = [
  13. {% for column in columns %}
  14. {% if column.is_required == 2 and column.is_pk != 2 %}
  15. '{{column.column_name}}' => 'require',
  16. {% endif %}
  17. {% endfor %}
  18. ];
  19. /**
  20. * 定义错误信息
  21. */
  22. protected $message = [
  23. {% for column in columns %}
  24. {% if column.is_required == 2 and column.is_pk != 2 %}
  25. '{{column.column_name}}' => '{{column.column_comment}}必须填写',
  26. {% endif %}
  27. {% endfor %}
  28. ];
  29. /**
  30. * 定义场景
  31. */
  32. protected $scene = [
  33. 'save' => [
  34. {% for column in columns %}
  35. {% if column.is_required == 2 and column.is_pk != 2 %}
  36. '{{column.column_name}}',
  37. {% endif %}
  38. {% endfor %}
  39. ],
  40. 'update' => [
  41. {% for column in columns %}
  42. {% if column.is_required == 2 and column.is_pk != 2 %}
  43. '{{column.column_name}}',
  44. {% endif %}
  45. {% endfor %}
  46. ],
  47. ];
  48. }