AdminValidate.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\admin\validate;
  3. class AdminValidate extends BaseValidate
  4. {
  5. /**
  6. * 设置校验规则
  7. * @var string[]
  8. */
  9. protected $rule = [
  10. 'id' => 'require',
  11. 'username' => 'require|min:1',
  12. 'nickname' => 'require|min:1',
  13. 'password' => 'require|min:6',
  14. 'phone' => 'nullable|min:11',
  15. 'email' => 'nullable|email',
  16. 'sex' => 'require|in:0,1',
  17. 'role_id' => 'integer',
  18. 'department_id' => 'integer',
  19. 'remark' => 'length:0,100',
  20. 'old_password' => 'require|min:6',
  21. 'password_confirmation' => 'require|min:6|confirm:password',
  22. ];
  23. /**
  24. * 参数描述
  25. * @var string[]
  26. */
  27. protected $field = [
  28. 'id' => 'id',
  29. 'username' => '账号',
  30. 'nickname' => '昵称',
  31. 'password' => '密码',
  32. 'phone' => '手机号',
  33. 'email' => '邮箱',
  34. 'sex' => '性别',
  35. 'role_id' => '角色ID',
  36. 'department_id' => '部门ID',
  37. 'remark' => '备注',
  38. 'old_password' => '旧密码',
  39. 'password' => '新密码',
  40. 'password_confirmation' => '确认密码',
  41. ];
  42. /**
  43. * @notes 添加场景
  44. */
  45. public function sceneAdd()
  46. {
  47. return $this->only(['username', 'nickname', 'password', 'phone', 'email', 'sex', 'role_id', 'department_id', 'remark']);
  48. }
  49. /**
  50. * @notes 编辑场景
  51. */
  52. public function sceneEdit()
  53. {
  54. return $this->only(['id','username', 'nickname', 'password', 'phone', 'email', 'sex', 'role_id', 'department_id', 'remark']);
  55. }
  56. public function sceneDel()
  57. {
  58. return $this->only(['id']);
  59. }
  60. public function scenePassword()
  61. {
  62. return $this->only(['old_password','password','password_confirmation']);
  63. }
  64. public function sceneLogin()
  65. {
  66. return $this->only(['username','password']);
  67. }
  68. }