Product.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. 'class_id' => 'required|integer|gt:0',
  26. 'code' => 'required',
  27. 'shop_name' => 'required',
  28. ];
  29. }
  30. // 场景列表
  31. protected $scenes = [
  32. 'get_list' => ['page','limit'],
  33. 'get_detail' => ['id'],
  34. 'get_sku' => ['id'],
  35. 'get_product' => ['class_id'],
  36. 'get_product_by_code' => ['code', 'shop_name'],
  37. ];
  38. /**
  39. * 获取已定义验证规则的错误消息
  40. *
  41. * @return array
  42. */
  43. public function messages()
  44. {
  45. return [
  46. 'id.required' => '请选择产品',
  47. 'id.integer' => '产品ID格式错误',
  48. 'id.gt' => '产品ID格式错误',
  49. 'page.integer' => '页码格式错误',
  50. 'page.gte' => '页码格式错误',
  51. 'limit.integer' => '取数格式错误',
  52. 'limit.gte' => '取数格式错误',
  53. 'class_id.required' => '请选择产品分类',
  54. 'class_id.integer' => '产品分类ID格式错误',
  55. 'class_id.gt' => '产品分类ID格式错误',
  56. ];
  57. }
  58. }