Custom.php 1.7 KB

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