Product.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php namespace App\Http\Requests\Api;
  2. use App\Http\Requests\BaseRequest;
  3. /**
  4. * 产品验证器
  5. *
  6. */
  7. class Product extends BaseRequest
  8. {
  9. /**
  10. * 获取应用于请求的规则
  11. *
  12. * @return array
  13. */
  14. public function rules()
  15. {
  16. // 编辑时排除ID
  17. // 返回结果
  18. return [
  19. // 有时候我们希望某个字段在第一次验证失败后就停止运行验证规则,只需要将 bail 添加到规则中:
  20. // 验证字段,验证规则,提示信息
  21. // 'name' => 'string|max:20',
  22. 'id' => 'required|integer|gt:0',
  23. 'page' => 'integer|gte:0',
  24. 'limit' => 'integer|gte:0',
  25. ];
  26. }
  27. // 场景列表
  28. protected $scenes = [
  29. 'get_list' => ['page','limit'],
  30. 'get_detail' => ['id'],
  31. 'get_sku' => ['id'],
  32. ];
  33. /**
  34. * 获取已定义验证规则的错误消息
  35. *
  36. * @return array
  37. */
  38. public function messages()
  39. {
  40. return [
  41. 'id.required' => '请选择产品',
  42. 'id.integer' => '产品ID格式错误',
  43. 'id.gt' => '产品ID格式错误',
  44. 'page.integer' => '页码格式错误',
  45. 'page.gte' => '页码格式错误',
  46. 'limit.integer' => '取数格式错误',
  47. 'limit.gte' => '取数格式错误',
  48. ];
  49. }
  50. }