Coupon.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php namespace App\Http\Requests\Api;
  2. use App\Http\Requests\BaseRequest;
  3. /**
  4. * 优惠券验证器
  5. *
  6. */
  7. class Coupon 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. 'coupon_id' => 'required|integer|gt:0',
  23. 'page' => 'integer|gte:0',
  24. 'limit' => 'integer|gte:0',
  25. ];
  26. }
  27. // 场景列表
  28. protected $scenes = [
  29. 'get_product' => ['coupon_id','page','limit'],
  30. ];
  31. /**
  32. * 获取已定义验证规则的错误消息
  33. *
  34. * @return array
  35. */
  36. public function messages()
  37. {
  38. return [
  39. 'coupon_id.required' => '请选择优惠券',
  40. 'coupon_id.integer' => '优惠券ID格式错误',
  41. 'coupon_id.gt' => '优惠券ID格式错误',
  42. 'page.integer' => '页码格式错误',
  43. 'page.gte' => '页码格式错误',
  44. 'limit.integer' => '取数格式错误',
  45. 'limit.gte' => '取数格式错误',
  46. ];
  47. }
  48. }