StoreUserRequest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Http\Requests\System;
  3. use App\Http\Models\Role;
  4. use App\Http\Requests\Request;
  5. use Illuminate\Database\Query\Builder;
  6. use Illuminate\Validation\Rule;
  7. class StoreUserRequest extends Request
  8. {
  9. /**
  10. * Determine if the user is authorized to make this request.
  11. *
  12. * @return bool
  13. */
  14. public function authorize()
  15. {
  16. return true;
  17. }
  18. /**
  19. * Get the validation rules that apply to the request.
  20. *
  21. * @return array
  22. */
  23. public function rules()
  24. {
  25. $addition = [];
  26. // if ($this->input('role_id') == Role::TYPE_CUSTOMER) {
  27. $addition['site_ids'] = 'nullable|array';
  28. // }
  29. return [
  30. 'nickname' => 'required',
  31. 'username' => [
  32. 'required',
  33. 'min:3',
  34. 'max:15',
  35. Rule::unique('users')->where(function (Builder $query) {
  36. return $query->where('deleted_at', null);
  37. })
  38. ],
  39. 'password' => 'min:5|max:15',
  40. 'phone' => [
  41. 'nullable',
  42. Rule::unique('users')->where(function (Builder $query) {
  43. return $query->where('deleted_at', null);
  44. })
  45. ],
  46. 'entry_time' => 'nullable',
  47. 'telephone' => 'nullable',
  48. 'email' => 'nullable',
  49. 'qq' => 'nullable',
  50. 'role_id' => 'required|numeric',
  51. 'status' => 'boolean',
  52. ] + $addition;
  53. }
  54. public function attributes()
  55. {
  56. return [
  57. 'nickname' => '昵称',
  58. 'username' => '用户名',
  59. 'password' => '密码',
  60. 'email' => '邮箱',
  61. 'qq' => 'qq号',
  62. 'role_id' => '角色',
  63. 'status' => '状态',
  64. 'sort' => '排序',
  65. 'site_id' => '站点',
  66. 'phone' => '手机号',
  67. 'telephone' => '座机',
  68. ];
  69. }
  70. }