Spec.php 1.3 KB

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